We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coding-Interviews-Golang/014-调整数组顺序使奇数位于偶数前面/problem014.go
Line 21 in cd7e47e
The text was updated successfully, but these errors were encountered:
确实变了,大概修改了一下:
package main import ( "fmt" ) func main() { items := []int{1, 2, 3, 4} oddFirst(items) fmt.Println(items) } func oddFirst(s []int) { if len(s) < 2 { return } i, j := len(s)-2, len(s)-1 for i >= 0 { if s[j]%2 == 0 { j-- } else if s[i]%2 == 0 { temp := s[i] copy(s[i:j], s[i+1:j+1]) s[j] = temp j-- i-- } else { i-- } } }
= >
[1 3 2 4]
Sorry, something went wrong.
No branches or pull requests
Coding-Interviews-Golang/014-调整数组顺序使奇数位于偶数前面/problem014.go
Line 21 in cd7e47e
The text was updated successfully, but these errors were encountered: