leetcode1184
Posted asenyang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode1184相关的知识,希望对你有一定的参考价值。
1 class Solution: 2 def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int: 3 if start == destination: 4 return 0 5 elif start < destination: 6 dis1,dis2 = 0,0 7 for i in range(start,destination): 8 dis1 += distance[i] 9 for i in range(start): 10 dis2 += distance[i] 11 for j in range(len(distance)-1,destination-1,-1): 12 dis2 += distance[j] 13 return min(dis1,dis2) 14 else: 15 dis1,dis2 = 0,0 16 start,destination = destination,start 17 for i in range(start,destination): 18 dis1 += distance[i] 19 for i in range(start): 20 dis2 += distance[i] 21 for j in range(len(distance)-1,destination-1,-1): 22 dis2 += distance[j] 23 return min(dis1,dis2)
以上是关于leetcode1184的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode 1184 公交站间的距离[数组] HERODING的LeetCode之路
LeetCode --- 1184. Distance Between Bus Stops 解题报告
leetcode 352 & leetcode 239 & leetcode 295 & leetcode 53 & leetcode 209