```
class Solution(object):
def nextPermutation(self, nums):
if not nums:
return []
if len(nums) == 1:
return nums
for i in xrange(len(nums)-2, -1, -1):
if nums[i] >= nums[i+1]:
pass
else:
for k in xrange(len(nums)-1, i,-1):
if nums[k] > nums[i]:
nums[k],nums[-1] = nums[-1],nums[k]
return nums[:i] + [nums[-1]] + nums[i:-1]
return nums[::-1]
```