1029. Two City Scheduling
Input: [[10,20],[30,200],[400,50],[30,20]][[10,20],[30,200] 會選擇前者class Solution {
public int twoCitySchedCost(int[][] costs) {
Arrays.sort(costs, (a, b) -> {
return (a[0] - a[1]) - (b[0] - b[1]);
});
int res = 0;
for (int i = 0; i < costs.length; i++) {
if (i < costs.length/2) {
res += costs[i][0];
} else {
res += costs[i][1];
}
}
return res;
}
}Previous874. Walking Robot SimulationNext1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
Last updated