Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 1f33341

Browse files
committed
905 finish
1 parent 8ec4e67 commit 1f33341

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package problem0905
22

33
func sortArrayByParity(a []int) []int {
4-
i, j, size := 0, len(a)-1, len(a)
5-
for i < j {
6-
for i < size && a[i]%2 == 0 {
4+
i, j := 0, len(a)-1
5+
for {
6+
for i < j && a[i]%2 == 0 {
77
i++
88
}
99
for i < j && a[j]%2 == 1 {
1010
j--
1111
}
12+
1213
if i < j {
1314
a[i], a[j] = a[j], a[i]
15+
} else {
16+
break
1417
}
18+
1519
}
1620
return a
1721
}

0 commit comments

Comments
 (0)