| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,18 @@ | |||
| 1 | + # @param {Integer[]} a | ||
| 2 | + # @return {Integer[]} | ||
| 3 | + def sort_array_by_parity(a) | ||
| 4 | + if a.length < 2 | ||
| 5 | + return a | ||
| 6 | + end | ||
| 7 | + | ||
| 8 | + left = [] | ||
| 9 | + right = [] | ||
| 10 | + a.length.times.each do | ||
| 11 | + if a[0].even? | ||
| 12 | + left << a.delete_at(0) | ||
| 13 | + else | ||
| 14 | + right << a.delete_at(0) | ||
| 15 | + end | ||
| 16 | + end | ||
| 17 | + a = left + right | ||
| 18 | + end | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments