Sort Array By Parity
https://leetcode.com/explore/learn/card/fun-with-arrays/511/in-place-operations/3260/
class Solution:
def sortArrayByParity(self, A: List[int]) -> List[int]:
i= 0
j = len(A)-1
while i < j:
if A[i] % 2 == 1 and A[j] % 2 == 0:
A[j],A[i] = A[i],A[j]
if A[i] % 2 == 0:
i+=1
if A[j] % 2 == 1:
j-=1
return A Brutal Force
Two Pointer
Last updated