add: 合并两个有序链表

This commit is contained in:
2020-05-01 17:25:01 +08:00
parent ecab5b8850
commit b665d6595e
4 changed files with 73 additions and 3 deletions

View File

@ -4,8 +4,8 @@
* @param {ListNode[]} right
*/
export const merge = (left, right) => {
const head = {}
let current = head
const dummyHead = {}
let current = dummyHead
while (left !== null && right !== null) {
if (left.val < right.val) {
if (left.val !== null) {
@ -28,7 +28,7 @@ export const merge = (left, right) => {
current.next = left
}
return head.next
return dummyHead.next
}
/**