class Solution { public: vector<int> productExceptSelf(vector<int>& nums) { if (nums.size() == 0) return vector<int>(); vector<int> res(nums.size(), 1); for (int i = 1; i < nums.size(); i++) { res[i] = res[i-1] * nums[i-1]; } int p = 1; for (int i = nums.size()-2; i >= 0; i--) { p = p * nums[i+1]; res[i] = res[i] * p; } return res; } };