class Solution {/**
递归深度根据k值确定,宽度的话那就[1,9]
因为递归不允许重复,那么的话我们需要每次在横向遍历的起始位置+1
*/
private List<List<Integer>> ans = new ArrayList<>();
private List<Integer> path = new ArrayList<>();
public intgetSum(List<Integer> list){int sum =0;for(Integer nums:list){
sum += nums;}return sum;}
public voidgetAns(int st,int k,int n){if(path.size()== k){if(getSum(path)== n) ans.add(new ArrayList<>(path));return;}for(int i = st; i <=9; i++){
path.add(i);getAns(i+1,k,n);
path.remove(path.size()-1);}}
public List<List<Integer>>combinationSum3(int k,int n){getAns(1,k,n);return ans;}}