```
class Solution:
# @param num, a list of integer
# @return a list of integer
def nextPermutation(self, num):
for i in range(len(num)-2, -1, -1):
for j in range(len(num)-1, i, -1):
if num[i] < num[j]:
num[i], num[j] = num[j], num[i]
return num[:i+1]+num[:i:-1]
return num[::-1]
```