//leetcode submit region begin(Prohibit modification and deletion)
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public int maxDepth(TreeNode root) {
if(root == null){
return 0;
}
int leftMaxDepth = maxDepth(root.left);
int rightMaxDepth = maxDepth(root.right);
int res = Math.max(leftMaxDepth, rightMaxDepth)+1;
return res;
}
}
//leetcode submit region end(Prohibit modification and deletion)
标签:right,TreeNode,最大,val,int,二叉树,深度,root,left
From: https://www.cnblogs.com/xiaoshahai/p/17079457.html