We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5fe9b18 commit ed599cdCopy full SHA for ed599cd
โmerge-two-sorted-lists/jinhyungrhee.javaโ
@@ -0,0 +1,29 @@
1
+class Solution {
2
+ public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
3
+
4
+ ListNode dummy = new ListNode(0);
5
+ ListNode current = dummy; // ***์ค์ ๋ก ๋ ธ๋๋ฅผ ์ด์ด๋๊ฐ ํฌ์ธํฐ***
6
7
+ while (list1 != null && list2 != null) {
8
+ if (list1.val < list2.val) {
9
+ current.next = list1;
10
+ list1 = list1.next;
11
+ }
12
+ else {
13
+ current.next = list2;
14
+ list2 = list2.next;
15
16
+ current = current.next;
17
18
19
+ // ๋จ์์๋ ๋ ธ๋๋ค ์ด์ด๋ถ์ด๊ธฐ
20
+ if (list1 != null) {
21
22
23
+ if (list2 != null) {
24
25
26
27
+ return dummy.next;
28
29
+}
0 commit comments