Merge two sorted lists
Easylinked listtwo pointersrecursion
a and b are linked lists sorted in ascending order. Merge them into one sorted list made of the same nodes and return its head.
Example 1
Input: a = [1,2,4], b = [1,3,4] Output: [1,1,2,3,4,4]
Example 2
Input: a = [], b = [0] Output: [0]
Constraints
- 0 ≤ nodes in each list ≤ 50
- -100 ≤ Node.val ≤ 100
- Both lists are sorted in non-decreasing order
Submit checks your solution against 8 tests, including hidden ones.
// Provided by the judge: keep these definitions
class ListNode {
constructor(val = 0, next = null) {
this.val = val
this.next = next
}
}
/**
* @param {ListNode|null} a
* @param {ListNode|null} b
* @return {ListNode|null}
*/
function mergeTwoLists(a, b) {
}