Skip to content

Commit f98cb41

Browse files
authored
Merge pull request #2299 from yeonjukim164/main
[yeonjukim164] WEEK 11 solutions
2 parents 931bcdf + 50c7acb commit f98cb41

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
3+
ListNode dummy = new ListNode(-1);
4+
ListNode curr = dummy;
5+
6+
while (list1 != null && list2 != null) {
7+
if (list1.val <= list2.val) {
8+
curr.next = list1;
9+
list1 = list1.next;
10+
} else {
11+
curr.next = list2;
12+
list2 = list2.next;
13+
}
14+
curr = curr.next;
15+
}
16+
17+
if (list1 != null) {
18+
curr.next = list1;
19+
} else if (list2 != null) {
20+
curr.next = list2;
21+
}
22+
23+
return dummy.next;
24+
}
25+
}

0 commit comments

Comments
 (0)