Should I contain the ListNode declaration inside my code? I encounter unreasonable errors to me when I submit my code either containing or not containing the ListNode part. After modifying the code several times now the error is "AttributeError: class ListNode has no attribute 'deserialize'".
Since there is no sample input, I do not know how to 'deserialize' it and I cannot test the code by myself. Would someone pleased to provide a sample?
I am a newer in python, too. Below is my test code.
class listNode: def __init__(self,x): self.val = x self.next = None def createList(a): if a is None: print 'no elements' return head=listNode(a) p=head i=1 n=len(a) while i<n: t=listNode(a[i]) p.next=t p=t i=i+1 return head def scanList(head): if head is None: print "no elements" return print head.val while head.next: p=head.next print p.val head=p