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 | 31 |
Tags
- hash table
- geometry
- Method
- bit manipulation
- simulation
- SQL
- Data Structure
- 파이썬
- dynamic programming
- two pointers
- Tree
- Stack
- database
- greedy
- Number Theory
- 코딩테스트
- 구현
- Binary Search
- Math
- 자바
- implement
- Class
- Matrix
- sorting
- java
- 코테
- Binary Tree
- Counting
- array
- string
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1232. Check If It Is a Straight Line 본문
1. Input
1) int[][] coordinates
- 점들의 x,y좌표가 담겨있다.
2. Output
1) 모든 점들이 한 직선 위에 있다면 true, 아니면 false를 반환
3. Constraint
1) 2 <= coordinates.length <= 1000
2) coordinates[i].length == 2
3) -10^4 <= coordinates[i][0], coordinates[i][1] <= 10^4
4) coordinates에는 중복되는 점이 없다.
4. Example
Input: coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,8]] -> Output: false
설명: (6,8)만 한 직선 위에 있지 않다.
5. Code
1) 첫 코드(2023/04/06)
int x1 = coordinates[1][0] - coordinates[0][0];
int y1 = coordinates[1][1] - coordinates[0][1];
boolean answer = true;
int i = 2;
while(i<coordinates.length && answer){
int x2 = coordinates[i][0] - coordinates[i-1][0];
int y2 = coordinates[i][1] - coordinates[i-1][1];
answer = x2*y1 == x1*y2;
i++;
}
return answer;
- 빠르지만 메모리를 많이 먹는 편이다.
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 1207. Unique Number of Occurrences (0) | 2023.04.06 |
---|---|
[LeetCode/Easy] 1217. Minimum Cost to Move Chips to The Same Position (0) | 2023.04.06 |
[LeetCode/Easy] 1128. Number of Equivalent Domino Pairs (0) | 2023.04.06 |
[LeetCode/Easy] 1160. Find Words That Can Be Formed by Characters (0) | 2023.04.06 |
[LeetCode/Easy] 1184. Distance Between Bus Stops (0) | 2023.04.05 |