Merge Two Sorted Lists

Easy

Topics
Linked ListRecursion

You are given the heads of two sorted linked lists l1 and l2. Splice them into one sorted list and return its head.

Example 1

Input:  l1 = [1,2,4], l2 = [1,3,4]
Output: [1,1,2,3,4,4]

Example 2

Input:  l1 = [], l2 = [0]
Output: [0]

Constraints

  • 0 <= list length <= 50
  • -100 <= Node.val <= 100
  • Both lists are sorted non-decreasing.
Run ⌘' · Submit ⌘⏎