Leetcode#148. Sort Listk
ProblemGiven the head of a linked list, return the list after sorting it in ascending order.
Example 1:
123Input: head = [4,2,1,3]Output: [1,2,3,4]
Example 2:
123Input: head = [-1,5,3,4,0]Output: [-1,0,3,4,5]
Example 3:
12Input: head = []Output: []
Solve1234567891011121314151617181920212223242526272829303132333435363738394041424344class Solution: def sortList(self, head: Optional[ListNode]) -> Optional[ListNode]: # 沒有 或只只有一個 代表已經排好了 if not head or not head.next: ...