merge-two-sorted-lists.sh — zsh

Merge Two Sorted Lists

easy
linked-listtwo-pointersrecursion

Merge two ascending linked lists and return the head of one sorted node chain.

Constraints

  • 0 <= total nodes <= 100
  • -100 <= node value <= 100
  • Both lists are sorted

Follow-up

Compare iterative O(1)-space merging with recursive merging.

Examples
Example 1
Input: list1 = [1,2,4], list2 = [1,3,4]
Output: [1,1,2,3,4,4]
Example 2
Input: list1 = [], list2 = []
Output: []
Example 3
Input: list1 = [], list2 = [0]
Output: [0]
🔒 5 hidden
Running will execute all 8 cases, including 5 hidden ones.