classSolution:defpermute(self, nums: List[int])-> List[List[int]]:from copy import copy
len_ =len(nums)if len_ in(0,1):return[nums]definsert2(_new, _ret):iflen(_ret)==0:return[[_new]]
ret =list()for l in _ret:for i inrange(len(l)+1):
tmp = copy(l)
tmp.insert(i, _new)
ret.append(tmp)return ret
ret =list()for i inrange(len_):
new_ = nums.pop()
ret = insert2(new_, ret)return ret