Why it will be wrong?

  • 0
    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    class Solution:
        # @param {ListNode} head
        # @return {ListNode}
        def sortList(self, head):
            if not head:
            tmp ,cur= [],head
            while cur.next != None:
                cur = cur.next
            tmp = sorted(tmp)
            cur = head
            for i in tmp:
                cur.val = i
                cur = cur.next
            return head

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.