Skip to content

Commit

Permalink
Merge pull request #814 from donghyeon95/main
Browse files Browse the repository at this point in the history
[donghyeon95] Week 4
  • Loading branch information
SamTheKorean authored Jan 5, 2025
2 parents 203a1c6 + c48048d commit f390a6f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
37 changes: 37 additions & 0 deletions merge-two-sorted-lists/donghyeon95.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
// O(N)
// 2포인터로 지나가용 하면 되는 문제
ListNode result = new ListNode();
ListNode nowNode = result;


while (list1!=null || list2!=null) {
int first = list1==null? 101: list1.val;
int second = list2==null? 101: list2.val;

if (first < second) {
nowNode.next = new ListNode(first);
nowNode = nowNode.next;
list1 = list1.next;
} else {
nowNode.next = new ListNode(second);
nowNode = nowNode.next;
list2 = list2.next;
}
}

return result.next;
}
}

19 changes: 19 additions & 0 deletions missing-number/donghyeon95.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

// O(N)
class Solution {
public int missingNumber(int[] nums) {
Set<Integer> numSet = Arrays.stream(nums).boxed().collect(Collectors.toSet());

for (int i=0; i<nums.length; i++) {
if (!numSet.contains(i)) return i;
}

return nums.length;
}
}

0 comments on commit f390a6f

Please sign in to comment.