剑指OFFER----面试题55

链接: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;
    }
}
原文地址:https://www.cnblogs.com/clown9804/p/12455093.html