Skip to content

Commit f390a6f

Browse files
authored
Merge pull request #814 from donghyeon95/main
[donghyeon95] Week 4
2 parents 203a1c6 + c48048d commit f390a6f

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* public class ListNode {
4+
* int val;
5+
* ListNode next;
6+
* ListNode() {}
7+
* ListNode(int val) { this.val = val; }
8+
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
9+
* }
10+
*/
11+
class Solution {
12+
public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
13+
// O(N)
14+
// 2포인터로 지나가용 하면 되는 문제
15+
ListNode result = new ListNode();
16+
ListNode nowNode = result;
17+
18+
19+
while (list1!=null || list2!=null) {
20+
int first = list1==null? 101: list1.val;
21+
int second = list2==null? 101: list2.val;
22+
23+
if (first < second) {
24+
nowNode.next = new ListNode(first);
25+
nowNode = nowNode.next;
26+
list1 = list1.next;
27+
} else {
28+
nowNode.next = new ListNode(second);
29+
nowNode = nowNode.next;
30+
list2 = list2.next;
31+
}
32+
}
33+
34+
return result.next;
35+
}
36+
}
37+

missing-number/donghyeon95.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java.util.Arrays;
2+
import java.util.Collections;
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
import java.util.stream.Collectors;
6+
7+
// O(N)
8+
class Solution {
9+
public int missingNumber(int[] nums) {
10+
Set<Integer> numSet = Arrays.stream(nums).boxed().collect(Collectors.toSet());
11+
12+
for (int i=0; i<nums.length; i++) {
13+
if (!numSet.contains(i)) return i;
14+
}
15+
16+
return nums.length;
17+
}
18+
}
19+

0 commit comments

Comments
 (0)