小编jas*_*ccc的帖子

Python:NameError:未定义全局名称“sortList”(递归期间)

l1 = sortList(head)递归行 ( ) 中,我得到NameError: global name 'sortList' is not defined. 谁能指出我哪里做错了?

class Solution:
    # @param head, a ListNode
    # @return a ListNode

    def sortList(self, head):
        if head == None or head.next == None:
            return head

        slow = head
        fast = head

        while fast != None and fast.next != None:
            slow = slow.next
            fast = fast.next.next
        fast = slow
        slow = slow.next
        fast.next = None
        l1 = sortList(head)
        l2 = sortList(slow)
        l = mergeTwoLists(l1, l2) …
Run Code Online (Sandbox Code Playgroud)

python recursion

4
推荐指数
1
解决办法
6227
查看次数

标签 统计

python ×1

recursion ×1