-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistbwbusstops.java
More file actions
28 lines (26 loc) · 818 Bytes
/
Copy pathdistbwbusstops.java
File metadata and controls
28 lines (26 loc) · 818 Bytes
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
27
28
class Solution {
public int distanceBetweenBusStops(int[] distance, int start, int destination) {
int d = Math.abs(destination - start);
int n = distance.length;
int t = n - d;
int dist = 0;
int dist2 = 0;
if (start > destination) {
int tmp = start;
start = destination;
destination = tmp;
}
for (int i = 0; i < d; i++) {
dist += distance[(start + i) % n];
System.out.println("Dist: " + dist);
}
for (int i = 0; i < t; i++) {
if ((destination + i) == start) {
continue;
}
dist2 += distance[(destination + i) % n];
System.out.println("Dist2: " + dist2);
}
return Math.min(dist, dist2);
}
}