Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- vector<vector<int>> combinationSum2(vector<int>& candidates, int target) {
- result.clear();
- solution.clear();
- can=candidates;
- sort(can.begin(),can.end());
- deal(0,target);
- return vector<vector<int>>(solution.begin(),solution.end());
- }
- void deal(int begin,int target)
- {
- if(target==0)
- {
- solution.insert(result);
- return;
- }
- for(int i=begin;i<can.size();++i)
- {
- if(target>=can[i])
- {
- result.push_back(can[i]);
- deal(i+1,target-can[i]);
- result.pop_back();
- }
- }
- }
- vector<int> can;
- vector<int> result;
- set<vector<int>> solution;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement