Why my solution can't pass the judging online?


  • 0
    Z
    my solution:
     if root==None:
         return 0
         highL=self.maxDepth(root.left)
         highR=self.maxDepth(root.right)
         if(highL<highR):
             return ++highR
         else:
             return ++highL
    
    what i saw from others:    
    def maxDepthHelper(root):
        if root==None: return 0
            return max(1+maxDepthHelper(root.left), 1+maxDepthHelper(root.right))
    
        return maxDepthHelper(root)

  • 0

    You need to find minimum depth of the tree , not maximum.


  • 0
    Z

    sorry,i chose the wrong question.It shoule be the Maximum Depth of Binary Tree...LOL


  • 0

    Yeah , no problem , it happens ;-)


Log in to reply
 

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