这是我第四遍做这道题,就这两句话啊,记不住,你说我没理解吧,每次也挺理解的。下次再错撞豆腐得了
public int maxDepth(TreeNode root) {
if(root==null)return 0;
return Math.max(maxDepth(root.left),maxDepth(root.right))+1;
}
重点在于最大深度就是左右子树的最大深度。
层序遍历也可,懒得做了
这是我第四遍做这道题,就这两句话啊,记不住,你说我没理解吧,每次也挺理解的。下次再错撞豆腐得了
public int maxDepth(TreeNode root) {
if(root==null)return 0;
return Math.max(maxDepth(root.left),maxDepth(root.right))+1;
}
重点在于最大深度就是左右子树的最大深度。
层序遍历也可,懒得做了