Easy
+1
None
表示到了根节点了,返回0
以上,尝试写一下代码,AC!
python3
class Solution:
def helper(self, node):
if node == None:
return 0
left_depth = 1 + self.helper(node.left)
right_depth = 1 + self.helper(node.right)
return max(left_depth,right_depth)
def maxDepth(self, root: TreeNode) -> int:
return self.helper(root)