My Java Solution


  • 0
    C
    public class Solution {
        public int maxDepth(TreeNode root) {
            if (root == null)
                return 0;
            if (root.left == null && root.right == null)
                return 1;
            
            int left = maxDepth(root.left) + 1;
            int right = maxDepth(root.right) + 1;
            return left <= right ? right : left;
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.