解题思路:使用set枚举,使用深度优先搜索,找到所有情况。
class Solution(object):
def permuteUnique(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
self.ans = []
self.tmp = []
def dfs(perm, s):
if not perm:
self.ans.append(s)
for i in set(perm):
tmp = perm[:]
tmp.remove(i)
dfs(tmp,s+[i])
dfs(nums, [])
return self.ans