1.给定一个数组,数组内含有重复元素,对数组中的元素进行全排列,输出排列组合
def unique(nums):##去掉重复的排列
begin=0;end=len(nums)
result=[]
if end==0:
result[[]]
permute_temp(begin,end,nums,result)
result.sort()
n=len(result)
i=0
while i<len(result)-1:
if result[i]==result[i+1]:
del result[i]
else:
i+=1
return result
def permute_temp(begin,end,nums,result):
if begin==end:
k=nums[:]
#print(k)
result.append(k)
else:
for i in range(begin,end):
temp=nums[begin];nums[begin]=nums[i];nums[i]=temp
permute_temp(begin+1,end,nums,result)
temp=nums[begin]
nums[begin]=nums[i]
nums[i]=temp
if __name__=="__main__":
nums=[1,3,2]
allresult=unique(nums)
print(allresult)
<