8000 21th problem · Adtrex/LeetcodeJs@79972d7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 79972d7

Browse files
committed
21th problem
1 parent 48cc474 commit 79972d7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

21. Merge Two Sorted Lists.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var mergeTwoLists = function(list1, list2) {
2+
let l = new ListNode(0);
3+
let head = l
4+
while(list1 != null && list2 != null){
5+
if(list1.val < list2.val){
6+
l.next = list1
7+
list1 = list1.next
8+
}else{
9+
l.next = list2
10+
list2 = list2.next
11+
}
12+
l = l.next
13+
}
14+
if (list1 == null) {
15+
l.next = list2;
16+
}
17+
else {
18+
l.next = list1;
19+
}
20+
return head.next
21+
};

0 commit comments

Comments
 (0)
0