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 54bde43 commit 5b11a4cCopy full SHA for 5b11a4c
merge-two-sorted-lists/sm9171.java
@@ -0,0 +1,20 @@
1
+class Solution {
2
+ public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
3
+ ListNode dummy = new ListNode(-1);
4
+ ListNode node = dummy;
5
+
6
+ while (list1 != null && list2 != null) {
7
+ if (list1.val < list2.val) {
8
+ node.next = list1;
9
+ list1 = list1.next;
10
+ } else {
11
+ node.next = list2;
12
+ list2 = list2.next;
13
+ }
14
+ node = node.next;
15
16
17
+ node.next = list1 != null ? list1 : list2;
18
+ return dummy.next;
19
20
+}
0 commit comments