본문 바로가기
Problem Solving

1-9. Two City Scheduling (LeetCode 1029)

by tls1107 2021. 7. 7.
728x90
반응형

 


class Solution {
    public int twoCitySchedCost(int[][] costs) {
        int n = costs.length;
        int answer = 0;
        java.util.Arrays.sort(costs, new java.util.Comparator<int[]>() {
            public int compare(int[] a, int[] b) {
                return Integer.compare(a[0]-a[1], b[0]-b[1]);}
            });
        for(int i = 0 ; i < n ; i++){
            if(i < n/2) answer += costs[i][0];
            else answer += costs[i][1];
        }
        return answer;
    }
}

https://leetcode.com/problems/two-city-scheduling/

 

Two City Scheduling - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

728x90
반응형

댓글