時間安排的不夠好
只能刷一道水題聊以自慰了
https://leetcode-cn.com/problems/sort-array-by-parity-ii/description/
還是類似于雙指針的方法通殃,一個奇數索引位置,一個偶數索引位置柳骄,如果放了元素后瑞凑,就往后跳
class Solution:
def sortArrayByParityII(self, A):
"""
:type A: List[int]
:rtype: List[int]
"""
ret = list(range(len(A)))
even = 0
odd = 1
for i in A:
if i % 2 == 0:
ret[even] = i
even += 2
else:
ret[odd] = i
odd +=2
return ret