LeetCode:1029 两地调度

class Solution {
    public int twoCitySchedCost(int[][] costs) {
      
        int len = costs.length;
        int t = len/2;
        Arrays.sort(costs,(a,b)->{return a[0]-a[1]-(b[0]-b[1]);});
        int res=0;
        for(int i=0;i<t;i++){
            res+=costs[i][0];
        }
        for(int i=t;i<len;i++){
            res+=costs[i][1];
        }
        return res;
    }
}

 

posted @ 2020-10-13 13:51  dlooooo  阅读(55)  评论(0编辑  收藏  举报