码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode1184

时间:2019-09-11 09:37:02      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:tco   class   lis   tar   solution   col   bsp   min   leetcode   

 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

标签:tco   class   lis   tar   solution   col   bsp   min   leetcode   

原文地址:https://www.cnblogs.com/asenyang/p/11504143.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!