[leetcode] 104. 二叉树的最大深度

104. 二叉树的最大深度

没什么好办法,深搜或者宽搜暴力遍历吧

class Solution {
    public int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
    }
}

猜你喜欢

转载自www.cnblogs.com/acbingo/p/9917338.html