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

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Linked Lists problems