Solution in Python 3 (beats ~96%) (short) ( O(1) space ) ( O(n) speed )
\nclass Solution:\n    def sortArrayByParity(self, A: List[int]) -> List[int]:\n        i, j = 0, len(A) - 1\n        while i < j:\n        \tif A[i] % 2 == 1 a
```\nclass Solution:\n    def sortArrayByParity(self, A: List[int]) -> List[int]:\n        i, j = 0, len(A) - 1\n        while i < j:\n        \tif A[i] % 2 == 1 and A[j] % 2 == 0: A[i], A[j] = A[j], A[i]\n        \ti, j = i + 1 - A[i] % 2, j - A[j] % 2\n        return A\n```\n*One Line Solutions:*\n```\nclass Solution:\n    def sortArrayByParity(self, A: List[int]) -> List[int]:\n        return sorted(A, key = lambda x : x % 2)\n\nclass Solution:\n    def sortArrayByParity(self, A: List[int]) -> List[int]:\n        return [i for i in A if not i % 2] + [i for i in A if i % 2]\n\n\n- Junaid Mansuri\n(LeetCode ID)@hotmail.com
['Python', 'Python3']