剑指OFFER----面试题55 - I. 二叉树的深度
链接:https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/
代码
/**
* 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) {
int cnt = 0;
if (root == null) return 0;
return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
}
}