classSolution{public:
vector<vector<int>> result;
vector<int> path;voidbacktracking(int targetSum , int startIndex , int k ,int sum){if(sum > targetSum){return;}if(path.size()== k){if(sum == targetSum){
result.push_back(path);}}for(int i = startIndex; i <9-(k-path.size())+1;i++){
sum += i;
path.push_back(i);backtracking(targetSum , i+1, k ,sum);
sum -=i;
path.pop_back();}}
vector<vector<int>>combinationSum3(int k, int n){backtracking(n ,1, k ,0);return result;}};