/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
int count = 0;
int max = 0;
public int maxDepth(TreeNode root) {
count++;
if(root != null) {
maxDepth(root.left);
count--;
max = Math.max(max,count);
maxDepth(root.right);
count--;
max = Math.max(max,count);
}
return max;
}
}
Maximum Depth of Binary Tree
最新推荐文章于 2024-07-29 18:00:00 发布