Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 5x 5x 5x 16x 9x 9x 9x 7x 7x 7x 5x 5x | import { ListNode } from './List'
export default function mergeTwoLists(
l1: ListNode<number> | null,
l2: ListNode<number> | null,
): ListNode<number> | null {
const head = new ListNode(0)
let tail = head
while (l1 !== null && l2 !== null) {
if (l1.val <= l2.val) {
tail.next = l1
l1 = l1.next
tail = tail.next
} else {
tail.next = l2
l2 = l2.next
tail = tail.next
}
}
tail.next = l1 !== null ? l1 : l2
return head.next
}
|