【medium】78. Subsets

求集合不重複的子集:python

下面python的寫法很好啊!app

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/51604217spa

相關文章
相關標籤/搜索