The title

There are n points on the plane whose positions are represented by integer coordinates points[I] = [xi, yi]. Calculate the minimum time (in seconds) required to access all of these points.

You need to move on the plane according to the following rules:

For every second, you can: move 1 unit length horizontally, or 1 unit length vertically, or cross the diagonal SQRT (2) units (think of as moving 1 unit length horizontally and 1 unit length vertically in one second). These points must be accessed in the order in which they appear in the array. When accessing a point, you can pass through points that appear after that point, but those points do not count as valid access.

Example 1: inputs: points = [[1,1],[3,4],[-1,0]] output: 7 explanation: an optimal access path is: [1, 1] - > [2] - > [3, 3] - > [3, 4] - > [2, 3] - > [1, 2] - > [0, 1] - > [- 1, 0] from [1, 1] to [3, 4] takes 3 seconds from [3, 4] to [- 1, 0] need to 4 seconds 7 seconds example 2: points = [[3,2],[-2,2]] output: 5Copy the code

Tip:

points.length == n 1 <= n <= 100 points[i].length == 2 -1000 <= points[i][0], points[i][1] <= 1000

Their thinking

class Solution: def minTimeToVisitAllPoints(self, points: List[List[int]]) -> int: res = 0 for i in range(1, len(points)): x1, y1 = points[i - 1][0], points[i - 1][1] x2, y2 = points[i][0], points[i][1] res += max(abs(x1-x2), Abs (y1, y2)) # # select x, y is the absolute value of the maximum return res if __name__ = = "__main__ ': Points = [[1,1],[3,4],[-1,0]] points = [[3, 2], [-2, 2]] ret = Solution(). MinTimeToVisitAllPoints (points) print(ret)Copy the code