腾讯五十题No.22 子集

题目链接
看来还得读写几个题才会有感觉

力扣的大佬是真的多

class Solution {
    
    List<List<Integer>> res;
    List<Integer> path;
    public List<List<Integer>> subsets(int[] nums) {
        res = new ArrayList<>();
        path = new ArrayList<>();
        res.add(new ArrayList<>(path));
        dfs(nums,0);
        return res;
    }
    public void dfs(int[] nums,int start){
        //i每次的值都为上一次递归中加1下来的值
        for(int i = start;i < nums.length;i++){
            path.add(nums[i]);
            res.add(new ArrayList<>(path));
            dfs(nums,i + 1);
            path.remove(path.size() - 1);
        }
    }
}

posted @   蹇爱黄  阅读(25)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
点击右上角即可分享
微信分享提示