/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public int maxDepth(TreeNode root) {
return recurr(root);
}
int recurr(TreeNode root){
if(root==null) return 0;
int l = recurr(root.left)+1;
int r = recurr(root.right)+1;
return Math.max(l,r);
}
}
求二叉树深度
最新推荐文章于 2022-01-22 23:18:33 发布