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 1873ea2 commit 3ab52a0Copy full SHA for 3ab52a0
Solutions/0021_Merge Two Sorted Lists.java
@@ -0,0 +1,26 @@
1
+class Solution
2
+{
3
+ public ListNode mergeTwoLists(ListNode list1, ListNode list2)
4
+ {
5
+ if(list1 == null) return list2;
6
+ else if(list2 == null) return list1;
7
+ ListNode result = new ListNode(0);
8
+ ListNode current = result;
9
+ while(list1 != null && list2!= null)
10
11
+ if(list1.val <= list2.val)
12
13
+ current.next = list1;
14
+ list1 = list1.next;
15
+ }
16
+ else
17
18
+ current.next = list2;
19
+ list2 = list2.next;
20
21
+ current = current.next;
22
23
+ current.next = list1 == null ? list2:list1;
24
+ return result.next;
25
26
+}
0 commit comments