Skip to content

Commit 89a7d37

Browse files
Update 31. 下一个排列.md
1 parent 31ba062 commit 89a7d37

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

Methodology/31. 下一个排列.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,32 @@ class Solution {
8282
nums[j] = temp;
8383
}
8484
}
85-
```
85+
```
86+
87+
88+
89+
Go:
90+
91+
```go
92+
func nextPermutation(nums []int) {
93+
i, j := 0, len(nums) - 1
94+
for ;j > 0; j-- {
95+
if nums[j] > nums[j - 1] {
96+
i = j - 1
97+
break
98+
}
99+
}
100+
for k := len(nums) - 1; k >= j; k-- {
101+
if nums[k] > nums[i] {
102+
nums[i], nums[k] = nums[k], nums[i]
103+
break
104+
}
105+
}
106+
107+
for k := len(nums) - 1; k > j; k, j = k - 1, j + 1 {
108+
nums[j], nums[k] = nums[k], nums[j]
109+
}
110+
return
111+
}
112+
```
113+

0 commit comments

Comments
 (0)