Medium · Linked Lists

Sort linked list

Given the head of a singly linked list, sort its nodes in ascending order and return the head of the sorted list.

Examples

Example 1

[4,2,1,3]

Output: [1, 2, 3, 4]

Example 2

[-1,5,3,4,0]

Output: [-1, 0, 3, 4, 5]

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Linked Lists problems