Skip to content

Practice Insertion Sort List

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#147
LeetCode Problem

Insertion Sort List

Problem Statement

Sort the singly linked list using insertion sort and return its new head. Grow a sorted chain by removing one node at a time from the remaining input and inserting it at the correct position among the nodes already processed. Continue until every input node belongs to the sorted chain.

Source: Insertion Sort List on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
head = [4,2,1,3]
Output
[1,2,3,4]

# Example 2

Input
head = [-1,5,3,4,0]
Output
[-1,0,3,4,5]

Constraints

The number of nodes in the list is in the range [1, 5000].
-5000 <= Node.val <= 5000

Related LeetCode Problems

Practice more problems similar to Insertion Sort List.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.