```
vector<int> productExceptSelf(vector<int>& nums) {
vector<int> result(nums.size(), nums.front());
for (int i = 0; i<nums.size() - 1; i++)
result[i + 1] = result[i] * nums[i + 1];
int temp = 1;
for (int i = nums.size() - 1; i >= 0; i--) {
if (i == 0)
result[i] = temp;
else
result[i] = result[i - 1] * temp;
temp *= nums[i];
}
return result;
}
```