Class Solution

java.lang.Object
g0101_0200.s0148_sort_list.Solution

public class Solution extends Object
148 - Sort List.<p>Medium</p> <p>Given the <code>head</code> of a linked list, return <em>the list after sorting it in <strong>ascending order</strong></em>.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/09/14/sort_list_1.jpg" alt="" /></p> <p><strong>Input:</strong> head = [4,2,1,3]</p> <p><strong>Output:</strong> [1,2,3,4]</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/09/14/sort_list_2.jpg" alt="" /></p> <p><strong>Input:</strong> head = [-1,5,3,4,0]</p> <p><strong>Output:</strong> [-1,0,3,4,5]</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> head = []</p> <p><strong>Output:</strong> []</p> <p><strong>Constraints:</strong></p> <ul> <li>The number of nodes in the list is in the range <code>[0, 5 * 10<sup>4</sup>]</code>.</li> <li><code>-10<sup>5</sup> <= Node.val <= 10<sup>5</sup></code></li> </ul> <p><strong>Follow up:</strong> Can you sort the linked list in <code>O(n logn)</code> time and <code>O(1)</code> memory (i.e. constant space)?</p>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details