冒泡排序思想,超时
# class ListNode: # def __init__(self, x): # self.val = x # self.next = None # # # @param head ListNode类 the head node # @return ListNode类 # class Solution: def sortInList(self , head ): # write code here # 冒泡排序 length = 0 p = head while p: length += 1 p = p.next for _ in range(length): pre = head while pre and pre.next: cur = pre.next if pre.val > cur.val: pre.val, cur.val = cur.val, pre.val pre = pre.next return head