pull/33/head
jaredliw 2021-07-14 13:14:56 +08:00
parent c0b72b6814
commit f7c6fe7abf
1 changed files with 44 additions and 1 deletions

View File

@ -15,7 +15,7 @@
1->1->2->3->4->4
```
AC
AC
@ -80,3 +80,46 @@ public:
};
```
JS Code:
```js
var mergeTwoLists = function(l1, l2) {
let headpro = new ListNode(-1);
let headtemp = headpro;
while (l1 && l2) {
//接上大的那个
if (l1.val >= l2.val) {
headpro.next = l2;
l2 = l2.next;
}
else {
headpro.next = l1;
l1 = l1.next;
}
headpro = headpro.next;
}
headpro.next = l1 != null ? l1:l2;
return headtemp.next;
};
```
Python Code:
```py
class Solution:
def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
headpro = ListNode(-1)
headtemp = headpro
while l1 and l2:
#
if l1.val >= l2.val:
headpro.next = l2
l2 = l2.next
else:
headpro.next = l1
l1 = l1.next
headpro = headpro.next
headpro.next = l1 if l1 is not None else l2
return headtemp.next
```