-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe1184.py
28 lines (22 loc) · 1.16 KB
/
e1184.py
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
class Solution:
def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:
counter, clockwise = start, start
counterDist, clockwiseDist = 0, 0
while not counter == destination and not clockwise == destination :
counter = (counter - 1 + len(distance)) % len(distance)
counterDist += distance[counter]
clockwiseDist += distance[clockwise]
clockwise = (clockwise + 1) % len(distance)
if (clockwise == destination) :
while not counter == destination and counterDist < clockwiseDist :
counter = (counter - 1 + len(distance)) % len(distance)
counterDist += distance[counter]
if counter == destination and counterDist < clockwiseDist :
return counterDist
return clockwiseDist
while not clockwise == destination and clockwiseDist < counterDist :
clockwiseDist += distance[clockwise]
clockwise = (clockwise + 1) % len(distance)
if clockwise == destination and clockwiseDist < counterDist:
return clockwiseDist
return counterDist