Skip to content
LC-1266 Easy LeetCode

1266. Minimum Time Visiting All Points

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 83% Topics: Array, Math, Geometry
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

class Solution(object):
    def minTimeToVisitAllPoints(self, points):
        """
        :type points: List[List[int]]
        :rtype: int
        """
        return sum(max(abs(points[i+1][0] - points[i][0]),
                       abs(points[i+1][1] - points[i][1]))
                   for i in xrange(len(points)-1))

Solution from kamyu104/LeetCode-Solutions · MIT