I get wrong results on my localhost and correct on server. Anyone can tell me why?

I have the following code:


//Definition for a binary tree node.
function TreeNode(val, left, right) {
    this.val = (val === undefined ? 0 : val)
    this.left = (left === undefined ? null : left)
    this.right = (right === undefined ? null : right)
}

/**
 * @param {TreeNode} root
 * @return {boolean}
 */
var isUnivalTree = function (root) {
    if (!root) return true;
    return traverse(root, root.val);
};

const traverse = function (node, val) {
    if (!node) return true;
    return node.val == val && traverse(node.left, val) && traverse(node.right, val);
}


console.log(isUnivalTree([1, 1, 1, 1, 1, null, 1])); // true;
console.log(isUnivalTree([2, 2, 2, 5, 2])); false;

If I run this code on my localhost, using node, I get true, true
If I submit this code on the server, It gets accepted. Can anyone tell me what code I am missing to be able to get same result on the localhost?

Comments (0)