Solution 1Iterative Cascade
NOT THE MOST EFFICIENT SOLUTION
from copy import deepcopy
class Solution:
'''
NOT THE MOST EFFICIENT SOLUTION
'''
def subsets(self, nums: List[int]) -> List[List[int]]:
output = [[]]
for n in nums:
l = len(output)
output = output + deepcopy(output)
for i in range(l):
output[i].append(n)
return outputpublic List<List<Integer>> subsets(int[] nums) {
List<List<Integer>> output = new ArrayList<>();
output.add(new ArrayList<Integer>());
for(Integer n: nums) {
int l = output.size();
for(int i=0; i<l; i++) {
List<Integer> newList = new ArrayList<>(output.get(i));
newList.add(n);
output.add(newList);
}
}
return output;
}