```
class Solution {
public:
vector<int> productExceptSelf(vector<int>& nums) {
vector<int> result(nums.size());
int before = 1;
for (int i = 0; i < nums.size(); i++){
result[i] = before;
before *= nums[i];
}
int after = 1;
for (int i = nums.size() - 1; i >= 0; i--){
result[i] *= after;
after *= nums[i];
}
return result;
}
};
```