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
给你一个长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积。
Input: [1,2,3,4] Output: [24,12,8,6]
The text was updated successfully, but these errors were encountered:
/** * @param {number[]} nums * @return {number[]} */ var productExceptSelf = function(nums) { const result = new Array(nums.length); let prefixLeft = 1; for (let i = 0; i < nums.length; i++) { result[i] = prefixLeft; prefixLeft *= nums[i]; } let prefixRight = 1; for (let i = nums.length - 1; i >= 0; i--) { result[i] *= prefixRight; prefixRight *= nums[i]; } return result; };
function productExceptSelf(nums: number[]): number[] { const result: number[] = new Array(nums.length); let prefixLeft = 1; for (let i = 0; i < nums.length; i++) { result[i] = prefixLeft; prefixLeft *= nums[i]; } let prefixRight = 1; for (let i = nums.length - 1; i >= 0; i--) { result[i] *= prefixRight; prefixRight *= nums[i]; } return result; };
Sorry, something went wrong.
No branches or pull requests
238. Product of Array Except Self
给你一个长度为 n 的整数数组 nums,其中 n > 1,返回输出数组 output ,其中 output[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积。
Example
Constraint
Note
Follow up
The text was updated successfully, but these errors were encountered: