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
- geometry
- bit manipulation
- implement
- 자바
- Class
- java
- dynamic programming
- hash table
- sorting
- Binary Search
- 파이썬
- Counting
- 코딩테스트
- Stack
- database
- 코테
- string
- greedy
- Matrix
- Binary Tree
- Math
- 구현
- SQL
- Data Structure
- Tree
- two pointers
- Method
- simulation
- Number Theory
- array
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1266. Minimum Time Visiting All Points 본문
1. Input
1) 점의 좌표를 담은 2차원 배열 points
2. Output
1) 주어진 점을 순서대로 모두 지나게 선을 그릴 때 걸리는 최소 시간
2) 1초에 위, 아래, 좌, 우로 1칸 이동하거나 대각선으로 1칸(루트2)만큼 이동할 수 있다.
3. Constraint
1) 1, 2, 3번 점을 순서대로 지나야 한다고 하면, 1번을 지난 후 3번을 통과해서 2번으로 갈 수 있지만, 이때 1번에서 3번으로 간 것은 방문한 것으로 세지 않는다.
2) 1 <= points.length <= 100
3) points[i].length == 2
4) -1000 <= points[i][0], points[i][1] <= 1000
4. Example
Input: points = [[1,1],[3,4],[-1,0]] -> Output: 7
설명:
- 최소 이동은 [1,1] -> [2,2] -> [3,3] -> [3,4] -> [2,3] -> [1,2] -> [0,1] -> [-1,0]이다.
- [1,1]에서 [3,4]까지 3초, [3,4]에서 [-1,0]까지 4초이므로, 7을 반환한다.
5. Code
1) 첫 코드(2022/06/14)
int x=0, y=0;
int times = 0;
for(int i=0 ; i<points.length-1 ; i++){
x = Math.abs(points[i][0] - points[i+1][0]);
y = Math.abs(points[i][1] - points[i+1][1]);
times += x>=y ? x : y;
}
return times;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 1290. Convert Binary Number in a Linked List to Integer (0) | 2022.12.24 |
---|---|
[LeetCode/Easy] 1281. Subtract the Product and Sum of Digits of an Integer (0) | 2022.12.24 |
[LeetCode/Easy] 1252. Cells with Odd Values in a Matrix (0) | 2022.12.24 |
[LeetCode/Easy] 1221. Split a String in Balanced Strings (0) | 2022.12.23 |
[LeetCode/Easy] 1154. Day of the Year (0) | 2022.12.20 |