47. Permutations II
2016-12-13 本文已影响0人
阿团相信梦想都能实现
class Solution(object):
def permuteUnique(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
def permute (res,nums,perm):
if not nums:
res.append(perm[:])
for i in xrange(len(nums)):
if (i==0 or nums[i]!=nums[i-1]):
perm.append(nums[i])
permute(res,nums[:i]+nums[i+1:],perm)
perm.pop()
res=[]
perm=[]
permute(res,sorted(nums),perm)
return res