class Solution { public: vector<int> productExceptSelf(vector<int>& nums) { vector<int> ans(nums.size(), 1); //>> calculate all the product before self for(int i = 1; i < nums.size(); i++) { ans[i] = ans[i-1] * nums[i-1]; } //>> calculate all the product after self //>> and find the ans int afterProduct = 1; for(int i = nums.size()-1; i >= 0; i--) { ans[i] *= afterProduct; afterProduct *= nums[i]; } return ans; } };