首页 > 其他分享 >day24 打卡第77题. 组合

day24 打卡第77题. 组合

时间:2023-03-24 13:23:47浏览次数:54  
标签:int day24 77 result new 打卡

day24 打卡第77题. 组合

第77题. 组合

77题目链接

class Solution {
    List<List<Integer>> result = new ArrayList<>();
    List<Integer> path = new LinkedList<>();
    
    public List<List<Integer>> combine(int n, int k) {
        combineHelper(n, k , 1);
        return result;
    }

    private void combineHelper(int n, int k, int startIndex){
        if (path.size() == k) {
            result.add(new ArrayList(path));
            return;
        }

        for (int i = startIndex ; i<=n - (k - path.size()) + 1 ; i++) {
            path.add(i);
            combineHelper(n, k, i+1);
            path.remove(path.size()-1);
        }
    }
}

参考资料

代码随想录

标签:int,day24,77,result,new,打卡
From: https://www.cnblogs.com/zzzsl/p/17251238.html

相关文章