-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowerSet.py
More file actions
51 lines (37 loc) · 782 Bytes
/
PowerSet.py
File metadata and controls
51 lines (37 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def powerSet(nums):
ans = [[]]
n = len(nums)
for num in nums:
count = len(ans)
for j in range(0,count):
temp = [ans[j][k] for k in range(0, len(ans[j]))]
temp.append(num)
ans.append(temp)
return ans
powerSet([1,2,3])
# PRINTED RECURSIVE VERSION
# def powerSet(n,s,i):
# if n < i:
# print(s)
# return
# powerSet(n,s + str(i),i+1)
# powerSet(n,s,i+1)
# PRINTED DP VERSION
# def powerSet(n):
# if(n == 0):
# print("")
# return
# if(n > 0):
# print("")
# print('1')
# mem = [["","1"]]
# i = 2
# while( i <= n):
# temp = []
# for arr in mem:
# for val in arr:
# per = val+ " " + str(i)
# print(per)
# temp.append(per)
# mem.append(temp)
# i += 1