```
class Solution {
public:
vector<int> productExceptSelf(vector<int>& nums) {
int size = nums.size();
vector<int> result(size, 1);
// upper triangle
for (int i = 1; i < size; i++)
{
result[i] = nums[i - 1] * result[i - 1];
}
int product = 1;
// lower triangle
for (int i = size - 2; i >= 0; i--)
{
product *= nums[i + 1];
result[i] *= product;
}
return result;
}
};
```

- Imagine calculating the product of each column of a matrix without the diagonal element

- Calculate upper triangle and lower triangle to get the answer