Skip to content

Commit 53e0f36

Browse files
add solution 03-june
1 parent 07da38a commit 53e0f36

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ out/
2424

2525
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2626
hs_err_pid*
27+
/leetcode.iml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* https://leetcode.com/explore/challenge/card/june-leetcoding-challenge/539/week-1-june-1st-june-7th/3348/
3+
*/
4+
public class DeleteNodeInLinkedList {
5+
6+
// WTF?
7+
public void deleteNode(ListNode node) {
8+
9+
node.val = node.next.val;
10+
node.next = node.next.next;
11+
12+
}
13+
14+
public class ListNode {
15+
int val;
16+
ListNode next;
17+
ListNode(int x) { val = x; }
18+
}
19+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.util.Arrays;
2+
3+
/**
4+
* See TwoCityScheduling_1029.java
5+
*/
6+
public class TwoCityScheduling {
7+
8+
public static int twoCitySchedCost(int[][] costs) {
9+
10+
int[] diff = new int[costs.length];
11+
int sum = 0;
12+
for (int i = 0; i < costs.length; i++) {
13+
diff[i] = costs[i][0] - costs[i][1];
14+
sum += costs[i][0];
15+
}
16+
17+
Arrays.sort(diff);
18+
19+
for (int i = diff.length / 2; i < diff.length; i++) {
20+
sum -= diff[i];
21+
}
22+
23+
return sum;
24+
}
25+
}

0 commit comments

Comments
 (0)