1. 程式人生 > >[leetcode] 104. 二叉樹的最大深度

[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;
    }
}