Java: 1ms recursive solution


  • 2
    A
    public int maxDepth(TreeNode node) {
            if (node == null) return 0;
            int left = maxDepth(node.left);
            int right = maxDepth(node.right);
            return (left > right ? left : right) + 1;
    }

Log in to reply
 

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