-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubset Sum
More file actions
40 lines (32 loc) · 833 Bytes
/
Copy pathSubset Sum
File metadata and controls
40 lines (32 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
void help(vector<int>nums,int n,vector<int>&t){
if(n==0)
{
t.push_back(0);
// return t;.
return;
}
// for(auto x:t)cout<<x<<" ";
// cout<<endl;
help(nums,n-1,t);
vector<int>ans=t;
for(auto x:ans){
// if(x==0)continue;
// else{
int u=x+nums[n-1];
t.push_back(u);
// }
}
// t.push_back(nums[n-1]);
// for(auto x:t)cout<<x<<" ";
// cout<<endl;
// cout<<"j"<<endl;
return ;
}
vector<int> subsetSum(vector<int> &nums){
// Write your code here.
vector<int>t;
sort(nums.begin(),nums.end());
help(nums,nums.size(),t);
sort(t.begin(),t.end());
return t;
}