in fact, this is just the combination of 2 loops to compute the left and right acculumated product. So we can combine the 2 loop into one loop as the below implementation.

class Solution {
public:
vector<int> productExceptSelf(vector<int>& nums) {
int n = nums.size();
int left = 1, right = 1;
vector<int> result(n, 1);
for (int i = 0; i < n; i++) {
result[i] *= left;
left *= nums[i];
//result[n-1-i] *= right;
//right *= nums[n-1-i];
}
for (int i = 0; i < n; i++) {
//result[i] *= left;
//left *= nums[i];
result[n-1-i] *= right;
right *= nums[n-1-i];
}
return result;
}
};