Failed Output: [object Object] for input [0]

  • 0

    Hi All,

    I'm using the following implementation, but always fail at [0] input. The output is [object Object] in the submission result. Testing in Chrome gets correct output { val: 0, left: null, right: null }.

    var sortedArrayToBST = function(num) {
        if (!num.length) return null;
        var mid = Math.floor(num.length / 2);
        return {
            val: num[mid],
            left: sortedArrayToBST(num.slice(0, mid)),
            right: sortedArrayToBST(num.slice(mid + 1, num.length))

Log in to reply

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