Created
April 15, 2020 22:57
-
-
Save RP-3/5801ee2c27de0651a468ae1d6ba6f849 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number[]} nums | |
* @return {number[]} | |
*/ | |
var productExceptSelf = function(nums) { | |
const left = new Array(nums.length).fill(1); | |
for(let i=1; i<nums.length; i++){ | |
left[i] = left[i-1]*nums[i-1]; | |
} | |
let multiplier = nums[nums.length-1]; | |
for(let i=nums.length-2; i>=0; i--){ | |
left[i] = left[i] * multiplier; | |
multiplier *= nums[i]; | |
} | |
return left; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment