826. Most Profit Assigning Work

思路:如何处理3个数组之间的映射关系

class Solution {
    public int maxProfitAssignment(int[] difficulty, int[] profit, int[] worker) {
        int[] index = new int[worker.length];

        for(int i = 0; i < worker.length;i++) {
            index[i] = getIndex(worker[i], difficulty, profit);
        }
        int total = 0;
        for(int i = 0; i < index.length; i++) {
            total += index[i];
        }
        return total;
    }
    
        private static int getIndex(int worker, int[] difficulty, int[] profit) {
        int max = 0;
        for(int i = 0;i < difficulty.length; i++) {
            if(worker >= difficulty[i] && profit[i] >= max) {
                max = profit[i];
            }
        }
        return max;
    }
}

猜你喜欢

转载自blog.csdn.net/Wengzhengcun/article/details/89501560
今日推荐