Runtime Error !! but work OK on my machine,help


  • 0
    L

    here is mine code,and it is Runtime Error.
    The Error info is "Line 38: AttributeError: 'NoneType' object has no attribute 'val' " ,but it can work on my mac. the Line 38 is "value = node.val". help !!

    class Solution:
    # @param root, a tree node
    # @return a list of lists of integers
    def zigzagLevelOrder(self, root):
        isEven = 1 
        evenQueue = []
        oddQueue = []  
        allResult = []
        evenQueue.append(root)
        onelevel = []
        
        while len(evenQueue) != 0 or len(oddQueue) != 0:
            queue=evenQueue
            if isEven == 1 :
                queue=evenQueue
            else :
                queue=oddQueue
                
            if len(queue) != 0 :
                node = queue[0]
                del queue[0]
            else :
                if isEven == 0 :
                    onelevel.reverse()
                    isEven = 1
                else :
                    isEven = 0
                allResult.append(onelevel)
                onelevel = []
                continue
            value = node.val
            onelevel.append(value)
            queue=oddQueue
            if isEven == 1 :
                queue=oddQueue
            else:
                queue=evenQueue
            if node.left != None:queue.append(node.left)
            if node.right != None:queue.append(node.right)
        if isEven == 1 :onelevel.reverse()
        allResult.append(onelevel)
        return allResult

Log in to reply
 

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