dfs二刷20200711
class Solution {
List<List<Integer>> res = new ArrayList();
Stack<Integer> path = new Stack();
public List<List<Integer>> combine(int n, int k) {
//k表示: 到终点还需要几个数
dfs(n, 1, k);
return res;
}
public void dfs(int n, int u, int k){
if(k == 0){
res.add(new ArrayList(path));
return;
}
for(int i = u; i <= n; i++){
path.push(i);
dfs(n, i+1, k-1);
path.pop();
}
}
}