From d75626834c9d743d2f39d9c66e91520a6eb19ece Mon Sep 17 00:00:00 2001 From: donghyeon95 Date: Sun, 29 Dec 2024 23:43:00 +0900 Subject: [PATCH 1/3] feat: Merge Two Sorted Lists #224 --- merge-two-sorted-lists/donghyeon95.java | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 merge-two-sorted-lists/donghyeon95.java diff --git a/merge-two-sorted-lists/donghyeon95.java b/merge-two-sorted-lists/donghyeon95.java new file mode 100644 index 000000000..99bc24013 --- /dev/null +++ b/merge-two-sorted-lists/donghyeon95.java @@ -0,0 +1,36 @@ +/** + * 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; + } +} \ No newline at end of file From dd5d98d2c82fad2e5e4c44f22da31f95bc577f1e Mon Sep 17 00:00:00 2001 From: donghyeon95 Date: Sun, 29 Dec 2024 23:43:22 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=EA=B0=9C=ED=96=89=20=EB=AC=B8=EC=9E=90=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- merge-two-sorted-lists/donghyeon95.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/merge-two-sorted-lists/donghyeon95.java b/merge-two-sorted-lists/donghyeon95.java index 99bc24013..e4f43c128 100644 --- a/merge-two-sorted-lists/donghyeon95.java +++ b/merge-two-sorted-lists/donghyeon95.java @@ -33,4 +33,5 @@ public ListNode mergeTwoLists(ListNode list1, ListNode list2) { return result.next; } -} \ No newline at end of file +} + From c48048d6b9d610ba400280ac730f9787e401cff2 Mon Sep 17 00:00:00 2001 From: donghyeon95 Date: Sun, 29 Dec 2024 23:55:50 +0900 Subject: [PATCH 3/3] feat: Missing Number #235 --- missing-number/donghyeon95.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 missing-number/donghyeon95.java diff --git a/missing-number/donghyeon95.java b/missing-number/donghyeon95.java new file mode 100644 index 000000000..03985af52 --- /dev/null +++ b/missing-number/donghyeon95.java @@ -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 numSet = Arrays.stream(nums).boxed().collect(Collectors.toSet()); + + for (int i=0; i