Skip to content

Commit 2154422

Browse files
refactor 1029
1 parent 98c5d76 commit 2154422

File tree

1 file changed

+4
-27
lines changed

1 file changed

+4
-27
lines changed

src/main/java/com/fishercoder/solutions/_1029.java

+4-27
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,13 @@
22

33
import java.util.Arrays;
44

5-
/**
6-
* 1029. Two City Scheduling
7-
*
8-
* There are 2N people a company is planning to interview.
9-
* The cost of flying the i-th person to city A is costs[i][0], and the cost of flying the i-th person to city B is costs[i][1].
10-
* Return the minimum cost to fly every person to a city such that exactly N people arrive in each city.
11-
*
12-
* Example 1:
13-
*
14-
* Input: [[10,20],[30,200],[400,50],[30,20]]
15-
* Output: 110
16-
* Explanation:
17-
* The first person goes to city A for a cost of 10.
18-
* The second person goes to city A for a cost of 30.
19-
* The third person goes to city B for a cost of 50.
20-
* The fourth person goes to city B for a cost of 20.
21-
*
22-
* The total minimum cost is 10 + 30 + 50 + 20 = 110 to have half the people interviewing in each city.
23-
*
24-
* Note:
25-
*
26-
* 1 <= costs.length <= 100
27-
* It is guaranteed that costs.length is even.
28-
* 1 <= costs[i][0], costs[i][1] <= 1000
29-
* */
305
public class _1029 {
316
public static class Solution1 {
32-
/**credit: https://leetcode.com/problems/two-city-scheduling/discuss/280173/Java-4-lines-intuitive-solution
7+
/**
8+
* credit: https://leetcode.com/problems/two-city-scheduling/discuss/280173/Java-4-lines-intuitive-solution
339
* and
34-
* https://leetcode.com/problems/two-city-scheduling/discuss/278771/Java-sort-solution*/
10+
* https://leetcode.com/problems/two-city-scheduling/discuss/278771/Java-sort-solution
11+
*/
3512
public int twoCitySchedCost(int[][] costs) {
3613
Arrays.sort(costs, (a, b) -> (a[0] - a[1] - (b[0] - b[1])));
3714
int cost = 0;

0 commit comments

Comments
 (0)