/**
* 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 Math.max(1+maxDepth(root.left),1+maxDepth(root.right));
}
}
剑指 Offer 55 - I. 二叉树的深度
最新推荐文章于 2024-09-03 18:29:17 发布