/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public int maxDepth(TreeNode root) {
if(root == null) {
return 0;
}
if(root.left == null && root.right == null) {
return 1;
}
int l = maxDepth(root.left);
int r = maxDepth(root.right);
return l >= r? l+1:r+1;
}
}
leetcode-java-104. Maximum Depth of Binary Tree
最新推荐文章于 2022-03-21 00:00:00 发布