We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]
Example 1: Input: nums = [1,2,3,4] Output: [24,12,8,6]
Example 2: Input: nums = [-1,1,0,-3,3] Output: [0,0,9,0,0]
It looks like we fliped the array, because we traverse from the back but get the result on the first index
var productExceptSelf = function(nums) { const res = []; let leftMult = 1; let rightMult = 1; for(let i = nums.length - 1; i >= 0; i--) { res[i] = rightMult; rightMult *= nums[i]; } for(let i = 0; i < nums.length; i++) { res[i] *= leftMult; leftMult *= nums[i]; } return res; };
The text was updated successfully, but these errors were encountered:
cheatsheet1999#1 removed unnecessary files from the repository
714fd26
No branches or pull requests
Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]
Example 1:
Input: nums = [1,2,3,4]
Output: [24,12,8,6]
Example 2:
Input: nums = [-1,1,0,-3,3]
Output: [0,0,9,0,0]
It looks like we fliped the array, because we traverse from the back but get the result on the first index
[24, 12, 4, 1]
[24, 12, 8, 6] leftMult was [1, 1, 2, 6]
The text was updated successfully, but these errors were encountered: