# 【Leet Code】238. Product of Array Except Self---Medium

Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].

Solve it without division and in O(n).

For example, given [1,2,3,4], return [24,12,8,6].

Could you solve it with constant space complexity? (Note: The output array does not count as extra space for the purpose of space complexity analysis.)

class Solution {
public:
vector<int> productExceptSelf(vector<int>& nums) {
vector<int> res(nums.size(), 1);

for(int i = 1; i < nums.size(); ++i)
res[i] = res[i-1] * nums[i-1];

int temp = nums.back();
for(int i = nums.size()-2; i >= 0; --i)
{
res[i] = res[i] * temp;
temp *= nums[i];
}

return res;

}
};

#### LeetCode 238： Product of Array Except Self

2015-07-27 18:51:41

#### leetcode 238: Product of Array Except Self

2015-07-16 14:40:04

#### [LeetCode]Product of Array Except Self,解题报告

2015-07-17 10:20:32

#### leetcode 238 Product of Array Except Self C++

2016-09-03 21:53:55

#### 238. Product of Array Except Self(Java)

2017-07-13 15:18:24

#### LeetCode238:Product of Array Except Self

2015-07-20 15:56:13

#### LeetCode算法题集-238. Product of Array Except Self（除自己外的数组项的乘积）

2018-02-08 09:50:32

#### 238. Product of Array Except Self

2016-02-24 10:09:12

#### 238. Product of Array Except Self **

2016-08-28 15:45:53

#### 238. Product of Array Except Self。

2018-01-05 16:08:55