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;
    }
}
posted @ 2020-11-13 02:31  EvanMeetTheWorld  阅读(19)  评论(0)    收藏  举报