- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1184.java
26 lines (24 loc) · 851 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
packagecom.fishercoder.solutions.secondthousand;
publicclass_1184 {
publicstaticclassSolution1 {
publicintdistanceBetweenBusStops(int[] distance, intstart, intdestination) {
if (start > destination) {
inttmp = start;
start = destination;
destination = tmp;
}
intclockwise = 0;
for (inti = start; i < destination; i++) {
clockwise += distance[i];
}
intcounterClockwise = 0;
for (inti = destination; i < distance.length; i++) {
counterClockwise += distance[i];
}
for (inti = 0; i < start; i++) {
counterClockwise += distance[i];
}
returnMath.min(clockwise, counterClockwise);
}
}
}