|
1 | 1 | package com.fishercoder.solutions;
|
2 | 2 |
|
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 |
| - * */ |
32 | 3 | public class _1266 {
|
33 | 4 | public static class Solution1 {
|
34 | 5 | /**
|
35 | 6 | * Time: O(n)
|
36 | 7 | * Space: O(1)
|
37 |
| - * |
| 8 | + * <p> |
38 | 9 | * credit: https://leetcode.com/problems/minimum-time-visiting-all-points/discuss/436142/Sum-of-Chebyshev-distance-between-two-consecutive-points
|
39 |
| - * */ |
| 10 | + */ |
40 | 11 | public int minTimeToVisitAllPoints(int[][] points) {
|
41 | 12 | int minTime = 0;
|
42 | 13 | for (int i = 0; i < points.length - 1; i++) {
|
|
0 commit comments