Skip to content

Latest commit

 

History

History
48 lines (39 loc) · 812 Bytes

90.Subsets II -python.md

File metadata and controls

48 lines (39 loc) · 812 Bytes
def dfs(sub,nums,startindex,res):
	res.append(sub[:])
	for i in range(startindex,len(nums)):
		sub.append(nums[i])            
		if res.count(sub) == 0:             # 78题加了一个判断条件
			dfs(sub,nums,i+1,res)
		sub.pop()



class Solution:
	def subsetsWithDup(self, nums):
	"""
        :type nums: List[int]
        :rtype: List[List[int]]
        """
	nums.sort()
	res=[]
	dfs([],nums,0,res)
	print(res)
	return res
	
-----------------------------------------------------
class Solution:
	def subsetsWithDup(self, nums):
	"""
        :type nums: List[int]
        :rtype: List[List[int]]
        """
	nums.sort()
	res=[[]]
	for num in nums:
		temp = []
		for ans in res:
			temp.append(ans+ [num])

		for x in temp:
			if res.count(x) ==0:
				res+=[x]

	return res