class Solution {
public int maximumUnits(int[][] boxTypes, int truckSize) {
int n = boxTypes.length;
Arrays.sort(boxTypes, Comparator.comparingInt(o -> o[1]));
int res = 0;
for (int i = n - 1; i >= 0 && truckSize > 0; i --) {
if (truckSize > boxTypes[i][0]) {
res += boxTypes[i][0] * boxTypes[i][1];
truckSize -= boxTypes[i][0];
} else {
res += truckSize * boxTypes[i][1];
return res;
}
}
return res;
}
}
标签:1710,卡车,int,res,truckSize,boxTypes,单元
From: https://www.cnblogs.com/eiffelzero/p/16893621.html