mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
17 lines
417 B
C
17 lines
417 B
C
int distanceBetweenBusStops(int* distance, int distanceSize, int start, int destination){
|
|
|
|
int sum1 = 0, sum2 = 0;
|
|
if (start > destination) {
|
|
int tmp = start;
|
|
start = destination;
|
|
destination = tmp;
|
|
}
|
|
for (auto i = 0; i < distanceSize; ++i) {
|
|
if (i >= start && i < destination)
|
|
sum1 += distance[i];
|
|
else
|
|
sum2 += distance[i];
|
|
}
|
|
return sum1 < sum2 ? sum1 : sum2;
|
|
}
|