赞
踩
- class Solution {
- private:
- vector<int> temp;
- vector<vector<int>> ans;
- public:
- void dfs(int k,int n,int cur) {
- if (temp.size()==k) {
- if(n==0) {
- ans.push_back(temp);
- }
- return;
- }
- if(n<0||cur>9) {
- return;
- }
- dfs(k,n,cur+1);
- temp.push_back(cur);
- dfs(k,n-cur,cur+1);
- temp.pop_back();
- return;
- }
- vector<vector<int>> combinationSum3(int k, int n) {
- dfs(k,n,1);
- return ans;
- }
- };
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。