leetcode 148对链表进行排序

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014204761/article/details/82932763
def sortList(self, head):
        '''
        1. 先把单链表的值存起来排序,
        2. 再生成有序链表
        '''
        listL = []
        p = cur = head
        while cur:
            listL.append(cur.val)
            cur = cur.next
        listL.sort()
        for i in listL:
            p.val = i
            p = p.next
        return head

猜你喜欢

转载自blog.csdn.net/u014204761/article/details/82932763
今日推荐