首页 > 其他分享 >1710. 卡车上的最大单元数

1710. 卡车上的最大单元数

时间:2022-11-15 19:46:09浏览次数:66  
标签:1710 卡车 int res truckSize boxTypes 单元

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;
    }
}

标签:1710,卡车,int,res,truckSize,boxTypes,单元
From: https://www.cnblogs.com/eiffelzero/p/16893621.html

相关文章