Merge Two Sorted Lists

Easy Solved

Description

You are given the heads of two sorted linked lists list1 and list2.

Merge the two lists into one sorted list. The list should be made by splicing together the nodes of the first two lists.

Return the head of the merged linked list.

Input format / Clarification:

To simplify execution in the web runner, the linked lists are provided as JSON arrays.

  • Line 1: JSON array representing list1
  • Line 2: JSON array representing list2

Examples

Input:

[1,2,4] [1,3,4]

Output: [1,1,2,3,4,4]

Input:

[] []

Output: []

Input:

[] [0]

Output: [0]

Note:

Your program must print the merged list as a JSON array so it can be compared with the expected output.

No submissions yet.

Discuss iterative vs recursive merging, pointer manipulation, and edge cases like empty lists.

Test Cases