Created
September 21, 2019 09:11
-
-
Save surinoel/cda61c93bfff1c3eccd790d0e705de3b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <string> | |
#include <vector> | |
using namespace std; | |
void go(int idx, int sum, const vector<int> &numbers, int &cnt, int target) { | |
if(idx == numbers.size()) { | |
if(sum == target) { | |
cnt += 1; | |
} | |
return; | |
} | |
go(idx + 1, sum + numbers[idx], numbers, cnt, target); | |
go(idx + 1, sum - numbers[idx], numbers, cnt, target); | |
} | |
int solution(vector<int> numbers, int target) { | |
int answer = 0; | |
go(0, 0, numbers, answer, target); | |
return answer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment