You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Given a set of candidate numbers(C)(without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.
*
* The Same repeated number may be chosen from C unlimited number of times.
*/
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
vector<vector<int>> combinationSum(vector<int>& candidates, int target) {
sort(candidates.begin(), candidates.end());
vector<vector<int>> ret;
vector<int> path;
findSum(candidates, target, path, ret, 0);
return ret;
}
void findSum(vector<int>& candidates, int target, vector<int>& path, vector<vector<int>>& ret, int begin) {
if (target == 0) {
ret.push_back(path);
return ;
}
for (int i = begin; i < candidates.size() && target >= candidates[i]; i++) {