easyLinked List 0 views

Merge Two Sorted Linked Lists

Splice two sorted singly-linked lists together into a single sorted list.

You are given the heads of two singly-linked lists, list1 and list2, where each list is sorted in non-decreasing order.

Merge the two lists into one sorted list by splicing together the nodes of the two lists, and return the head of the merged list.

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]

Constraints

  • The number of nodes in both lists combined is in the range [0, 100].
  • -100 <= Node.val <= 100
  • Both list1 and list2 are sorted in non-decreasing order.

Hints

Companies

No companies reported yet.

Discussion

Sign in to join the discussion.

Loading discussion...

Test results

No test cases yet.