第九周——LeetCode

xiaoxiao2021-02-28  40

Given a set of distinct integers, nums, return all possible subsets (the power set).

Note: The solution set must not contain duplicate subsets.

class Solution(object): def subsets(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ l = len(nums) answer = [[]] for i in range(0,l): n = [] n.append(nums[i]) answer2 = [] if n not in answer: for value in answer: answer2.append(value[:]) value.append(nums[i]) answer = answer2[:]+answer return answer
转载请注明原文地址: https://www.6miu.com/read-2626604.html

最新回复(0)