function subsets(nums: number[]): number[][] {
let list: number[][] = new Array()
list.push([])
for (let i1 = 0; i1 < nums.length; i1++) {
const len = list.length
for (let i2 = 0; i2 < len; i2++) {
list.push([...list[i2], nums[i1]])
}
}
return list
}
py
class Solution:
def subsets(self, nums: List[int]) -> List[List[int]]:
list = [[]]
for i in range(len(nums)):
leng = len(list)
for i2 in range(leng):
list.append(list[i2]+[nums[i]])
return list
C#
public class Solution {
public IList<IList<int>> Subsets(int[] nums) {
IList<IList<int>> list = new List<IList<int>>(){};
List<int> kk = new List<int>(){};
list.Add(kk);
for(int i1 = 0;i1<nums.Length;i1++){
int len = list.ToArray().Length;
for(int i2 = 0;i2<len;i2++){
List<int> ll = new List<int>(list[i2]);
ll.Add(nums[i1]);
list.Add(ll);
}
}
return list;
}
}