Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitad21bce

Browse files
refactor 1266
1 parent6b1a73f commitad21bce

File tree

1 file changed

+2
-31
lines changed

1 file changed

+2
-31
lines changed

‎src/main/java/com/fishercoder/solutions/_1266.java

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,13 @@
11
packagecom.fishercoder.solutions;
22

3-
/**
4-
* 1266. Minimum Time Visiting All Points
5-
*
6-
* On a plane there are n points with integer coordinates points[i] = [xi, yi].
7-
* Your task is to find the minimum time in seconds to visit all points.
8-
*
9-
* You can move according to the next rules:
10-
* In one second always you can either move vertically, horizontally by one unit or diagonally
11-
* (it means to move one unit vertically and one unit horizontally in one second).
12-
* You have to visit the points in the same order as they appear in the array.
13-
*
14-
* Example 1:
15-
* Input: points = [[1,1],[3,4],[-1,0]]
16-
* Output: 7
17-
* Explanation: One optimal path is [1,1] -> [2,2] -> [3,3] -> [3,4] -> [2,3] -> [1,2] -> [0,1] -> [-1,0]
18-
* Time from [1,1] to [3,4] = 3 seconds
19-
* Time from [3,4] to [-1,0] = 4 seconds
20-
* Total time = 7 seconds
21-
*
22-
* Example 2:
23-
* Input: points = [[3,2],[-2,2]]
24-
* Output: 5
25-
*
26-
* Constraints:
27-
* points.length == n
28-
* 1 <= n <= 100
29-
* points[i].length == 2
30-
* -1000 <= points[i][0], points[i][1] <= 1000
31-
* */
323
publicclass_1266 {
334
publicstaticclassSolution1 {
345
/**
356
* Time: O(n)
367
* Space: O(1)
37-
*
8+
* <p>
389
* credit: https://leetcode.com/problems/minimum-time-visiting-all-points/discuss/436142/Sum-of-Chebyshev-distance-between-two-consecutive-points
39-
* */
10+
*/
4011
publicintminTimeToVisitAllPoints(int[][]points) {
4112
intminTime =0;
4213
for (inti =0;i <points.length -1;i++) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp