Would someone pleased to provide a sample input and output for Python?


  • 2
    I

    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?


  • 0
    D

    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[0])
    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

Log in to reply
 

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