Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

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 ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access