题目链接
https://leetcode-cn.com/problems/permutations-ii/
方法1 回溯
class Solution:
def permuteUnique(self, nums: List[int]) -> List[List[int]]:
o=[]
def huisu(dangqianzhuangtai,kexuanzhuangtai):
if not kexuanzhuangtai and dangqianzhuangtai not in o:
o.append(dangqianzhuangtai)
if not kexuanzhuangtai:
return
# kexuanzhuangtai=kexuanzhuangtai
for i in kexuanzhuangtai:
t=dangqianzhuangtai[:]
t.append(i)
kz=kexuanzhuangtai[:]
kz.remove(i)
huisu(t,kz)
huisu([],nums)
return o