Skip to content

Commit 73afd69

Browse files
authored
Merge branch 'DaleStudy:main' into main
2 parents 3c6be3e + f98cb41 commit 73afd69

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

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)