Python codes error, but works on local machine


  • 0
    C

    Following is my python codes, and it passes on my local machine. But after my submission here, the error message appeared like this:

    Runtime Error Message:	Line 12: AttributeError: 'NoneType' object has no attribute 'left'
    Last executed input:	{}
    

    Can anyone help me a little bit? Thanks in advance!

    # Definition for a  binary tree node
    #class TreeNode:
    #    def __init__(self, x):
    #        self.val = x
    #        self.left = None
    #        self.right = None
    
    class Solution:
    # @param root, a tree node
    # @return an integer
    def maxDepth(self, root):
        if root==None:
            return 0
        else:
            if root.left!=None:
                lmax=maxDepth(root.left)
            else:
                lmax=0
            if root.right!=None:
                rmax=maxDepth(root.right)
            else:
                rmax=0
            return max(lmax, rmax)+1

  • 0
    C

    It was correct now.

    lmax=maxDepth(root.left) 
    

    should be

    lmax=self.maxDepth(root.left)
    

    My bad...


Log in to reply
 

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