# 下一个排列

<p>实现获取 <strong>下一个排列</strong> 的函数，算法需要将给定数字序列重新排列成字典序中下一个更大的排列。</p><p>如果不存在下一个更大的排列，则将数字重新排列成最小的排列（即升序排列）。</p><p>必须<strong><a href="https://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95" target="_blank"> 原地 </a></strong>修改，只允许使用额外常数空间。</p><p> </p><p><strong>示例 1：</strong></p><pre><strong>输入：</strong>nums = [1,2,3]<strong><br />输出：</strong>[1,3,2]</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>nums = [3,2,1]<strong><br />输出：</strong>[1,2,3]</pre><p><strong>示例 3：</strong></p><pre><strong>输入：</strong>nums = [1,1,5]<strong><br />输出：</strong>[1,5,1]</pre><p><strong>示例 4：</strong></p><pre><strong>输入：</strong>nums = [1]<strong><br />输出：</strong>[1]</pre><p> </p><p><strong>提示：</strong></p><ul>	<li><code>1 <= nums.length <= 100</code></li>	<li><code>0 <= nums[i] <= 100</code></li></ul>

## template

```python
class Solution(object):
	def nextPermutation(self, nums):
		ls = len(nums)
		if ls <= 1:
			return
		pair = []
		for i in range(ls):
			for j in range(i + 1, ls):
				if nums[i] < nums[j]:
					pair.append([i,j])
		pos = 0
		if len(pair) > 0:
			self.swap(nums, pair[-1][0], pair[-1][1])
			pos = pair[-1][0] + 1
		for i in range(pos, ls):
			for j in range(i + 1, ls):
				if nums[i] > nums[j]:
					self.swap(nums, i, j)
		return nums
	def swap(self, nums, index1, index2):
		if index1 == index2:
			return
		nums[index1], nums[index2] = nums[index2], nums[index1]
# %%
s = Solution()
print(s.nextPermutation(nums = [1,2,3]))
```

## 答案

```python

```

## 选项

### A

```python

```

### B

```python

```

### C

```python

```