Possible Bug with Javascript: "Run Code" and "Submit Solution" give different results for same test case


  • 0
    G

    For the test case [1,1,1] , "Run Code" returns the answer 2 but "Submit Solution" returns the answer 0

    /**
     * @param {number[]} nums
     * @return {number}
     */
    
    var sMap = {};
    
    var rob = function(nums) {
        sMap[0] = 0;
        sMap[1] = nums[0];
        sMap[2] = Math.max(nums[0], nums[1]);
       
        function findSol(m) {
            if (sMap[m] !== undefined) {
                return sMap[m];
            }
            sMap[m] = Math.max(findSol(m-2) + nums[m - 1], findSol(m-1));
            return sMap[m];
        }
        
        return findSol(nums.length);
    };
    

  • 0
    J

    try "clear you global variable every time entering your function"


Log in to reply
 

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