class Solution {
public int maxDepth(TreeNode root) {
if(root == null) return 0;
return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
}
}
class Solution {
public int maxDepth(TreeNode root) {
if(root == null) return 0;
return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
}
}
下一篇:5. 最长回文子串
【数据结构】第五章——树与二叉树详细介绍二叉树的存储结构……
写在前面难度:简单递归 + 高度更新解题思想(化繁为简!!!)问题转化巧妙树的深度为左子树的深度和右子树
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M