Leetcode 1266. Minimum Time Visiting All Points

dadumvu·2020년 6월 8일
0
post-thumbnail


class Solution:
    def minTimeToVisitAllPoints(self, points: List[List[int]]) -> int:
        # point[0] <-- x
        # point[1] <-- y
        # max(abs(x+1 - x), abs(y+1, y))
        x = points[0][0]
        y = points[0][1]
        res = 0
        for i, group in enumerate(points):
            if i == 0: continue
            x = abs(x - group[0])
            y = abs(y - group[1])
            res += max(x, y)
            x = group[0]
            y = group[1]
            
        return res
        

https://leetcode.com/problems/minimum-time-visiting-all-points/

0개의 댓글