@@ -0,0 +1,901 @@
+package leetcode;%0A%0Aimport java.util.Arrays;%0A%0A/**%0A * https://leetcode.com/problems/two-city-scheduling/%0A */%0Apublic class Problem1029 %7B%0A    public int twoCitySchedCost(int%5B%5D%5B%5D costs) %7B%0A        Arrays.sort(costs, (c1, c2) -%3E Math.abs(c2%5B0%5D - c2%5B1%5D) - Math.abs(c1%5B0%5D - c1%5B1%5D));%0A        int answer = 0;%0A        int aCount = 0;%0A        int bCount = 0;%0A        for (int%5B%5D cost : costs) %7B%0A            if (aCount == costs.length / 2) %7B%0A                answer += cost%5B1%5D;%0A                bCount++;%0A            %7D else if (bCount == costs.length / 2) %7B%0A                answer += cost%5B0%5D;%0A                aCount++;%0A            %7D else %7B%0A                if (cost%5B0%5D %3C= cost%5B1%5D) %7B%0A                    answer += cost%5B0%5D;%0A                    aCount++;%0A                %7D else %7B%0A                    answer += cost%5B1%5D;%0A                    bCount++;%0A                %7D%0A            %7D%0A        %7D%0A        return answer;%0A    %7D%0A%7D%0A

Solve problem 1029