We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class Solution { public: vector<vector<int>> combinationSum2(vector<int>& candidates, int target) { vector<vector<int>> result; vector<int> currentCombination; sort(candidates.begin(), candidates.end()); backTrack(candidates, target, 0, currentCombination, result); return result; } private: void backTrack(vector<int>& candidates, int target, int index, vector<int>& currentCombination, vector<vector<int>>& result) { if (target == 0) { result.push_back(currentCombination); return; } if (target < 0) return; for (int i = index; i < candidates.size(); i++) { if (i > index && candidates[i] == candidates[i - 1]) continue; currentCombination.push_back(candidates[i]); backTrack(candidates, target - candidates[i], i + 1, currentCombination, result); currentCombination.pop_back(); } } };
Combination Sum
The text was updated successfully, but these errors were encountered:
fkdl0048
No branches or pull requests
Combination Sum
문제랑 비슷한 개념으로 중복을 허용하지 않기에, 정렬한 후 중복을 제거하는 로직을 추가한다.The text was updated successfully, but these errors were encountered: