void doit(vector<int>& nums, int idx, int prod, vector<int>& res) {
for(int i=idx; i<nums.size(); i++) {
int prodi = prod * nums[i];
res.push_back(prodi);
doit(nums, i+1, prodi, res);
}
}
vector<int> productExceptSelf(vector<int>& nums) {
vector<int> res;
doit(nums, 0, 1, res);
return res;
}
No comments:
Post a Comment