//url:https://leetcode.com/problems/sort-array-by-parity/
func sortArrayByParity(A []int) []int {
startIndex := 0
endIndex := len(A) - 1
for startIndex < endIndex {
if 0 != A[startIndex]%2 {
for startIndex < endIndex {
if 0 == A[endIndex]%2 {
fmt.Println(“startIndex=”, startIndex, “,endIndex=”, endIndex, “swap:”, A[startIndex], “,”, A[endIndex])
tmp := A[startIndex]
A[startIndex] = A[endIndex]
A[endIndex] = tmp
endIndex–
break
}
endIndex–
}
}
startIndex++
}
return A
}
- 本文作者: royalchen
- 本文链接: http://www.royalchen.com/2018/12/20/leetcode-905-sort-array-by-parity/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!