class Solution(object):
def permute1(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
ret=[nums,]
for i in xrange(len(nums)-1):
for r in ret[:]:
for j in xrange(i+1,len(nums)):
newnums=r[:]
newnums[i],newnums[j]=newnums[j],newnums[i]
ret.append(newnums)
return ret
def permute2(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
if len(nums)==0:
return [[]]
ret=[]
for i in xrange(len(nums)):
nums[0],nums[i]=nums[i],nums[0]
subret=self.permute(nums[1:])
for v in subret:
v.append(nums[0])
ret.append(v)
return ret
def permute(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
import itertools
return itertools.permutations(nums)