/**
* 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) {
if(root == null){
return 0;
}
return Core(root);
}
public int Core(TreeNode root){
int count = 0;
int left = 0;
int right = 0;
if(root == null){
return 1;
}
if(root.left != null){
left = Core(root.left);
}
if(root.right != null){
right = Core(root.right);
}
return Math.max(right,left)+1;
}
}
20200707——第一百零四题 二叉树的最大深度
最新推荐文章于 2020-07-14 00:02:08 发布