Incorrect/Faulty Test Case?


  • 0
    C

    Is one test case incorrect?

    I have:

    var rightSideView = function(root) {
        var outArr = [];
        console.log(root);
        if(root === null){
            return outArr;
        }
        else if(root.right === null){
            return outArr.concat(root.val);
        }
        else{
            var valArr = [root.val];
            return outArr.concat(valArr.concat(rightSideView(root.right)));
        }
    };
    

    And for testcase: [1,2]
    my output is:
    TreeNode {
    val: 1,
    right: null,
    left: TreeNode { val: 2, right: null, left: null } }

    As you can see, the right node is null, and the left node has value. Since we are only interested in the right side, I believe output should be: [1] but the test says it's supposed to be [1,2]. Is the test case incorrect?


Log in to reply
 

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