78. Subsets
https://leetcode.com/problems/subsets/
js
/**
* @param {number[]} nums
* @return {number[][]}
*/
var subsets = function(nums) {
var result = [
[]
]
for (let i = 0; i < nums.length; i++) {
let size = result.length
for (let j = 0; j < size; j++) {
result.push(result[j].concat([nums[i]]))
}
}
return result
}
py
class Solution(object):
def subsets(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
result = [[]]
for i in range(len(nums)):
size = len(result)
for j in range(size):
result.append(result[j] + [nums[i]])
return result