class Solution {
public int distanceBetweenBusStops(int[] distance, int start, int destination) {
int n = distance.length, i = start, j = start, a = 0, b = 0 ;
while (i != destination){
a += distance[i];
if (++i == n){
i = 0;
}
}
while (j != destination){
if (--j < 0){
j = n - 1;
}
b += distance[j];
}
return Math.min(a, b);
}
}
力扣:1184. 公交站间的距离
最新推荐文章于 2024-07-25 17:15:51 发布