package
0.0.0-20241220224003-b7cf03a90b2b
Repository: https://github.com/szhou12/leetcode-go.git
Documentation: pkg.go.dev
# README
922. Sort Array By Parity II
Solution idea
Naive Solution
- 开两个数组分别存下偶数元素,奇数元素; 再合并起来
Time complexity = $O(n)$, Space complexity = $O(n)$
In-place
- 检查每个偶数位置,如果发现是奇数元素,则从奇数位置从小到大找存有偶数元素的,进行交换
Time complexity = $O(n)$, Space complexity = $O(1)$