首页 > 其他分享 >第一次正式接触回溯,看完视频后,开始上手

第一次正式接触回溯,看完视频后,开始上手

时间:2023-01-06 00:12:24浏览次数:34  
标签:视频 int 接触 new backTracing result 回溯 path size

第77题. 组合

class Solution {
    LinkedList<Integer> path =new LinkedList<>();
    List<List<Integer>> result = new ArrayList<>();
    public List<List<Integer>> combine(int n, int k) {
        backTracing(n,k,0);
        return result;
    }
    public void backTracing(int n,int size,int startIndex){
        if(path.size()==size){
            result.add(new ArrayList<>(path));
            return;
        }
        for (int i = startIndex; i < n-(size-path.size())+1; i++) {
            path.add(i+1);
            backTracing(n,size,i+1);
            path.removeLast();
        }
    }
}ava

标签:视频,int,接触,new,backTracing,result,回溯,path,size
From: https://www.cnblogs.com/Chain-Tian/p/17029232.html

相关文章