Skip to content

Commit 410936f

Browse files
author
deamlv
committed
[update]
1 parent 69691f9 commit 410936f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class TwoCityScheduling {
2+
public int twoCitySchedCost(int[][] costs) {
3+
int sum = 0;
4+
int[] ar = new int[2000];
5+
for (int[] iArray : costs) {
6+
sum = sum + iArray[0];
7+
ar[iArray[1] - iArray[0] +1000]++;
8+
}
9+
int index = 0;
10+
int i = 0;
11+
while (i < costs.length / 2) {
12+
while (ar[index] > 0 && i<costs.length/2) {
13+
sum = sum + (index -1000);
14+
ar[index]--;
15+
i++;
16+
}
17+
index++;
18+
}
19+
return sum;
20+
}
21+
}

0 commit comments

Comments
 (0)