1710. 卡车上的最大单元数
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;
}
}