Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6b5cb3f

Browse files
author
Yeqi Tao
authored
feat: add go solution to lc problem: No.0031 (doocs#829)
* feat: add go solution to lc problem: No.0202 * feat: add go solution to lc problem: No.0031
1 parent 2e7f134 commit 6b5cb3f

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

‎.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
/lcof/lcof.json
1010
/lcof/lcof_list.json
1111
/lcci/lcci.json
12-
/solution/__pycache__
12+
/solution/__pycache__
13+
*.iml
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
type sortInt []int
2+
3+
func (s sortInt) Len() int {
4+
return len(s)
5+
}
6+
7+
func (s sortInt) Less(i, j int) bool{
8+
return s[i] > s[j]
9+
}
10+
11+
func (s sortInt) Swap(i, j int) {
12+
s[i], s[j] = s[j], s[i]
13+
}
14+
15+
func nextPermutation(nums []int) {
16+
newNums := sortInt(nums)
17+
if sort.IsSorted(newNums) {
18+
n := sort.Reverse(newNums)
19+
sort.Sort(n)
20+
return
21+
}
22+
for i := len(nums) -2 ; i >= 0 ; i-- {
23+
for j := len(nums) - 1 ; j > i ; j-- {
24+
if nums[i] < nums[j] {
25+
nums[i],nums[j] = nums[j], nums[i]
26+
sort.Sort(sort.Reverse(newNums[i+1:]))
27+
return
28+
}
29+
}
30+
}
31+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /