- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSolution1029.java
More file actions
Latest commit
executable file
·36 lines (30 loc) · 885 Bytes
/
Copy pathSolution1029.java
File metadata and controls
executable file
·36 lines (30 loc) · 885 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
29
30
31
32
33
34
35
36
importjava.util.ArrayList;
importjava.util.Arrays;
importjava.util.HashMap;
importjava.util.List;
/**
* Created by slade on 2019/7/19.
*/
publicclassSolution1029 {
publicinttwoCitySchedCost(int[][] costs) {
intcandidate = costs.length;
int[] vals = newint[candidate];
intans = 0;
for (inti = 0; i < candidate; i++) {
// 去A比去B贵的程度
vals[i] = costs[i][0] - costs[i][1];
// 全去B花多少钱
ans += costs[i][1];
}
Arrays.sort(vals);
for (inti = 0; i < candidate/2; i++) {
ans+=vals[i];
}
returnans;
}
publicstaticvoidmain(String[] args) {
Solution1029s = newSolution1029();
int[][] val = {{10,20},{30,200},{400,50},{30,20}};
System.out.println(s.twoCitySchedCost(val));
}
}