Back to course home
0% completed
Vote For New Content
Sort List (medium)
Problem Statement
Given a head
of the linked list, return the list after sorting it in ascending order.
Examples
-
Example 1:
- Input:
[3, 1, 2]
- Expected Output:
[1, 2, 3]
- Justification: The list is sorted in ascending order, with
1
coming before2
, and2
before3
.
- Input:
-
Example 2:
- Input:
[4]
- Expected Output:
[4]
- Justification: A list with a single element is already sorted.
- Input:
-
Example 3:
- Input:
[9, 8, 7, 6, 5, 4, 3, 2, 1]
- Expected Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
- Justification: The list is sorted in ascending order, with each element being smaller than the next.
- Input:
Constraints:
- The number of nodes in the list is in the range [0, 5 * 10<sup>4</sup>].
- -10<sup>5</sup> <= Node.val <= 10<sup>5</sup>
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible