Given a binary tree, find its maximum depth.
# 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(not root): return 0 lDep=self.maxDepth(root.left) rDep=self.maxDepth(root.right) lrMaxDep=lDep if lDep>rDep else rDep return lrMaxDep+1
No comments :
Post a Comment