Created
June 25, 2022 05:23
-
-
Save webber2408/92d06684404a57516ab77cd128ed58c1 to your computer and use it in GitHub Desktop.
All Subset Sum Increasing Order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void recurse(int index, int N, vector<int> &num, vector<int> &sum, int sumSoFar){ | |
if(index == N){ | |
sum.push_back(sumSoFar); | |
return; | |
} | |
recurse(index+1, N, num, sum, sumSoFar+num[index]); | |
recurse(index+1, N, num, sum, sumSoFar); | |
return; | |
} | |
vector<int> subsetSum(vector<int> &num) | |
{ | |
// Write your code here. | |
vector<int> sum; | |
recurse(0, num.size(), num, sum, 0); | |
sort(sum.begin(), sum.end()); | |
return sum; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment