Skip to content

Instantly share code, notes, and snippets.

@RP-3
Created April 15, 2020 22:57
Show Gist options
  • Save RP-3/5801ee2c27de0651a468ae1d6ba6f849 to your computer and use it in GitHub Desktop.
Save RP-3/5801ee2c27de0651a468ae1d6ba6f849 to your computer and use it in GitHub Desktop.
/**
* @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