DEV Community

Karleb
Karleb

Posted on

#78. Subsets

https://leetcode.com/problems/subsets/description/?envType=daily-question&envId=2024-05-24

/**
 * @param {number[]} nums
 * @return {number[][]}
 */
var subsets = function(nums) {
    let res = [[]]

    for (let num of nums) {
        let n = res.length 
        for (let i = 0; i < n; i++) {
            let curr = [...res[i]]
            curr.push(num)
            res.push(curr)
        }
    }
    return res
};

Enter fullscreen mode Exit fullscreen mode

Top comments (0)