LeetCode 104. Maximum Depth of Binary Tree
clearly we can use recursion to solve this problem.
and the recursion equation will be:
maxDepth(root) = Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
class Solution {
public int maxDepth(TreeNode root) {
if (root == null) return 0;
return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
}
}

浙公网安备 33010602011771号