1287. Distance Between Bus Stops
My accepted Python solution to LeetCode problem 1287, Distance Between Bus Stops, running in 39ms.
- Difficulty: Easy
- Python
- Runtime 39ms
- Memory 18.3MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 39ms, memory 18.3MB, accepted 2025-12-30.
class Solution:
def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:
if start > destination:
start, destination = destination, start
clockwise = sum(distance[start:destination])
total = sum(distance)
counterclockwise = total - clockwise
return min(clockwise, counterclockwise)