-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path709_to_lower_case.py
More file actions
38 lines (24 loc) · 880 Bytes
/
709_to_lower_case.py
File metadata and controls
38 lines (24 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from typing import List
class Solution:
def minTimeToVisitAllPoints(self, points: List[List[int]]) -> int:
seconds = 0
init_x, init_y = points[0]
for point in points[1:]:
final_x, final_y = point
while init_x != final_x and init_y != final_y:
if final_x > init_x:
init_x += 1
if final_y > init_y:
init_y += 1
if final_x < init_x:
init_x -= 1
if final_y < init_y:
init_y -= 1
seconds += 1
if init_x == final_x and init_y == final_y:
seconds += 1
init_x, init_y = final_x, final_y
return seconds
if __name__ == '__main__':
points = [[3, 2], [-2, 2]]
print(Solution().minTimeToVisitAllPoints(points))