Python 3. 4 different ways with explanation
These are the 4 ways i do this problem\n\npython\nclass Solution:\n\t# use custom sort\n    def sortArrayByParity0(self, A: List[int]) -> List[int]: #96 ms\n   
These are the 4 ways i do this problem\n\n```python\nclass Solution:\n\t# use custom sort\n    def sortArrayByParity0(self, A: List[int]) -> List[int]: #96 ms\n        return sorted(A, key=lambda x: x % 2)\n    \n\t# Append to 2 different lists and join them when return.\n    def sortArrayByParity3(self, A: List[int]) -> List[int]: #100 ms\n        o = []; e = []\n        for num in A:\n            if num % 2 == 0: e.append(num)\n            else: o.append(num)\n        return e + o\n    \n\t# When left is odd, decrease right until right is even or right>left, then switch them\n    def sortArrayByParity2(self, A: List[int]) -> List[int]: #88 ms\n        left = 0; right = len(A) - 1\n        while right >= left:            \n            if A[left] % 2:\n                while right > left and A[right] % 2 :\n                    right -= 1\n                A[right], A[left] = A[left], A[right]\n            left += 1\n        return A    \n    \n\t# Same as above, however, slightly different logic.\n\t# Increase left if left is even\n\t# Decrease right if right is odd\n\t# Switch them if left is odd and right is even. \n\t# As you can imagine. Which ever stop increasing/decreasing first will have to wait for the other\n    def sortArrayByParity1(self, A: List[int]) -> List[int]: #96ms\n        left = 0; right = len(A) - 1\n        while right >= left:            \n            if A[left] % 2 == 1 and A[right] % 2 == 0:\n                A[right], A[left] = A[left], A[right]\n                left += 1\n                right -= 1\n            if A[left] % 2 == 0: left += 1            \n            if A[right] % 2 == 1: right -= 1\n        return A    \n```
['Python', 'Python3']