Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. class Solution {
  2. public:
  3. vector<vector<int>> combinationSum3(int k, int n) {
  4. solution.clear();
  5. answer.clear();
  6. if(k>9||n>45)
  7. return solution;
  8. deal(1,k,n);
  9. return solution;
  10. }
  11. void deal(int begin,int remain,int target)
  12. {
  13. if(target==0&&remain==0)
  14. {
  15. solution.push_back(answer);
  16. return;
  17. }
  18.  
  19. for(int i=begin;i<=9&&target>=i;++i)
  20. {
  21. answer.push_back(i);
  22. deal(i+1,remain-1,target-i);
  23. answer.pop_back();
  24. }
  25. }
  26. vector<int> answer;
  27. vector<vector<int>> solution;
  28. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement