Why this Java solution has LTE problem?

  • 0

    Why my code do the same thing as the second toppest solution does(as I commented), but when I submit it, the page gives me an TLE(Time Limit Exceed), do you guys know the reason? Thanks

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

Log in to reply

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