class Solution {
public List<List<Integer>> combine(int n, int k) {
List <List<Integer>> result =new ArrayList<>();
backtracking(n,k,result,1,new ArrayList<>());
return result;
}
public void backtracking(int n ,int k,List<List<Integer>> result,int begin ,ArrayList<Integer> list)
{
if(list.size()==k){
result.add(new ArrayList<>(list));
return;
}
for(int i=begin;i<=n;i++)
{
list.add(i);
backtracking(n,k,result,i+1,list);
list.remove(list.size()-1);
}
}
}
每日一练(lc77)
最新推荐文章于 2024-09-09 00:44:52 发布