Distance Between Bus Stops LeetCode solution in Python

1
class Solution:
2
def distanceBetweenBusStops(
3
self, distance: List[int], start: int, destination: int
4
) -> int:
5
# switch start and destination if destination is before start
6
if start > destination:
7
start, destination = destination, start
8
# find minimum for clockwise and counterclockwise direction
9
return min(
10
sum(distance[start:destination]),
11
sum(distance[:start] + distance[destination:]),
12
)

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0