In the line (l1 = sortList(head)) for recursion, I get NameError: global name 'sortList' is not defined.
Could anyone point out where I did wrong?
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)
return l