Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- Math
- simulation
- Counting
- implement
- java
- Matrix
- Number Theory
- Method
- hash table
- dynamic programming
- geometry
- 코테
- database
- Tree
- array
- SQL
- Data Structure
- 파이썬
- Stack
- sorting
- Binary Tree
- 구현
- Binary Search
- bit manipulation
- 코딩테스트
- Class
- two pointers
- greedy
- 자바
- string
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1037. Valid Boomerang 본문
1. Input
1) int[][] points
- 세 점의 좌표를 담고 있다.
2. Output
1) 세 점으로 부메랑을 만들 수 있다면 true를, 없다면 false를 반환
- 부메랑은 한 직선 위에 있지 않은 서로 다른 세 점을 말한다.
3. Constraint
1) points.length == 3
2) points[i].length == 2
3) 0 <= xi, yi <= 100
4. Example
Input: points = [[1,1],[2,3],[3,2]] -> Output: true
Input: points = [[1,1],[2,2],[3,3]] -> Output: false
5. Code
1) 첫 코드(2023/04/04)
boolean answer;
int x1 = points[1][0] - points[0][0];
int x2 = points[2][0] - points[1][0];
double y1 = points[1][1] - points[0][1];
double y2 = points[2][1] - points[1][1];
if((x1==0 && y1==0) || (x2==0 && y2==0))
answer = false;
else if(x1!=0 && x2!=0)
answer = y1/x1 != y2/x2;
else{
if(x1==0)
answer = x2!=0;
else
answer = x1!=0;
}
return answer;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 1184. Distance Between Bus Stops (0) | 2023.04.05 |
---|---|
[LeetCode/Easy] 1047. Remove All Adjacent Duplicates In String (0) | 2023.04.04 |
[백준 온라인 저지] 9506. 약수들의 합 (0) | 2023.04.04 |
[백준 온라인 저지] 5086. 배수와 약수 (0) | 2023.04.04 |
[백준 온라인 저지] 10757. 큰 수 A+B (0) | 2023.04.04 |