What is wrong of my JavaScript code?


  • 0
    S

    I tried to use traverse to solve the problem.
    '''
    var depth = 0;

    function depthHelper(curt, curtDepth){
    if(curt === null){
    return;
    }
    depth = Math.max(depth, curtDepth);
    depthHelper(curt.left, curtDepth + 1);
    depthHelper(curt.right, curtDepth + 1);
    }

    var maxDepth = function(root) {
    if(root === null){
    return 0;
    }
    depthHelper(root, 1);
    return depth;
    };
    '''
    I can not pass the test case [0,0,0,0,null,null,0,null,null,null,0] when I submit, but I tried it in Custom Testcase it is correct. What's wrong with it?


Log in to reply
 

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