# Definition for a binary tree node. # class TreeNode: # def __init__(self,x): # self.val = x # self.left = None # self.right = None class Solution: def maxDepth(self,root: TreeNode) -> int: if root==None: return 0 count = self.getDepth(root,0) return count def getDepth(self,node,count): if node!=None: num1 = self.getDepth(node.left,count+1); num2 = self.getDepth(node.right,count+1); num = num1 if num1>num2 else num2 return num else: return count@H_404_0@时间和空间消耗: @H_404_0@
@H_404_0@以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。