[Python3] 2-pointer
Even & odd indices \n1) maintain two indices "even" and "odd" which start at 0 and 1 spectively;\n2) loop through elements in array;\n3) if element is of odd pa
Even & odd indices \n1) maintain two indices "even" and "odd" which start at 0 and 1 spectively;\n2) loop through elements in array;\n3) if element is of odd parity, copy it to position of "odd" index and increase odd by two; if element is of even parity, copy it to positon of "even" index and increase even by two.\n```\nclass Solution:\n    def sortArrayByParityII(self, A: List[int]) -> List[int]:\n        ans = [None] * len(A)\n        index = [0, 1] #even & odd indices\n        for x in A:\n            ans[index[x%2]] = x\n            index[x%2] += 2\n        return ans \n```\n\nAn alternative implementation which updates A in place is as below. \n```\nclass Solution:\n    def sortArrayByParityII(self, nums: List[int]) -> List[int]:\n        ii, i = 0, 1\n        while ii < len(nums) and i < len(nums): \n            if not nums[ii] & 1: ii += 2\n            elif nums[i] & 1: i += 2\n            else: \n                nums[ii], nums[i] = nums[i], nums[ii]\n                ii += 2\n                i += 2\n        return nums\n```
['Python3']