Merge sort我研一上学期时候的笔记:
148. Sort List
简直就是我的笔记的代码版本。
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def sortList(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
if head is None or head.next is None:
return head
# step1 cut the list into two halves
prev, slow, fast = None, head, head
while fast is not None a