Skip to main content

🟡 剑指 Offer II 079. 所有子集

LeetCode 提示

题目难度 中等

原题链接 🔗 leetcode

题解1#

class Solution {    private List<List<Integer>> res = new ArrayList<>();
    public List<List<Integer>> subsets(int[] nums) {        res.add(new ArrayList<>());
        for (int num : nums) {            int n = res.size();            for (int i=0; i<n; i+=1) {                var newSubRes = new ArrayList<>(res.get(i));                newSubRes.add(num);                res.add(newSubRes);            }        }
        return res;    }}