求集合不重复的子集:
下面python的写法很好啊!
class Solution(object):
def subsets(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
res = [[]]
for num in nums :
for temp in res[:] :
x = temp[:]
x.append(num)
res.append(x)
return res
if __name__ == '__main__':
x=Solution()
res = x.subsets({1,2,3})
for r in res:
print(r)
其他的详细参考:https://blog.csdn.net/happyaaaaaaaaaaa/article/details/51604217