forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_1184.java
26 lines (24 loc) · 836 Bytes
/
_1184.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.fishercoder.solutions;
public class _1184 {
public static class Solution1 {
public int distanceBetweenBusStops(int[] distance, int start, int destination) {
if (start > destination) {
int tmp = start;
start = destination;
destination = tmp;
}
int clockwise = 0;
for (int i = start; i < destination; i++) {
clockwise += distance[i];
}
int counterClockwise = 0;
for (int i = destination; i < distance.length; i++) {
counterClockwise += distance[i];
}
for (int i = 0; i < start; i++) {
counterClockwise += distance[i];
}
return Math.min(clockwise, counterClockwise);
}
}
}