给定两个整数 n 和 k,返回范围 [1, n] 中所有可能的 k 个数的组合。
你可以按 任何顺序 返回答案。
示例一:
示例二:
思路分析:
代码展示:
class Solution {
List> ans=new ArrayList<>();
linkedList temp=new linkedList<>();
public List> combine(int n, int k) {
combineHelper(n,k,1);
return ans;
}
public void combineHelper(int n, int k, int startIndex){
if(temp.size()==k){
ans.add(new ArrayList<>{temp});
return;
}
for(int i=startIndex;i<=n;i++){
temp.add(i);
combineHelper(n,k,i+1);
temp.removeLast();
}
}
}



