Solution 1
- TimeO(n)
- SpaceO(1)
Where, n is number of points.
Simple Greedy problem.
Python · 2026-01-12
class Solution:
'''
Time Complexity: O(n)
Space Complexity: O(1)
Where, n is number of points.
Simple Greedy problem.
'''
def minTimeToVisitAllPoints(self, points: List[List[int]]) -> int:
time = 0
for i in range(1, len(points)):
hr = abs(points[i][0] - points[i-1][0])
ve = abs(points[i][1] - points[i-1][1])
time += max(hr, ve)
return time