#1266

Minimum Time Visiting All Points

newbie · 130 · lc easy +13 · verified · 84.8% accepted · 2,737 likes · top 96%

Description

On a 2D plane, you must visit the integer-coordinate points in points in the exact order given.

In one second you can move:

- One unit horizontally,

- One unit vertically, or

- One unit diagonally (one step both horizontally and vertically).

You must visit points in order, but you may pass through later-listed points without counting them as visited.

Return the total minimum time in seconds to visit all points.

Example 1:

Input: points = [[1,1],[3,4],[-1,0]]
Output: 7
Explanation: One optimal path is [1,1] -> [2,2] -> [3,3] -> [3,4] -> [2,3] -> [1,2] -> [0,1] -> [-1,0]
Time from [1,1] to [3,4] = 3 seconds
Time from [3,4] to [-1,0] = 4 seconds
Total time = 7 seconds

Example 2:

Input: points = [[3,2],[-2,2]]
Output: 5

Code

1
2
3