In-Place Swap - Python
Simply iterate the array keeping the index of the last known odd number. If arr[i] is even, swap it with arr[last_odd_idx]. This will ensure that the odd number
Simply iterate the array keeping the index of the last known odd number. If arr[i] is even, swap it with arr[last_odd_idx]. This will ensure that the odd numbers \'bubble\' to the end of the array and as a bonus we keep the same array structure (i.e., [1,3,2,4] becomes [2,4,1,3])\n\nTime complexity: O(N)\nSpace complexity: O(1)\n\n```class Solution:\n    def sortArrayByParity(self, nums: List[int]) -> List[int]:\n        \n        last_odd_idx = 0\n        \n        for i in range(len(nums)):\n            is_even = nums[i] % 2 == 0\n            if is_even:\n                nums[i], nums[last_odd_idx] = nums[last_odd_idx], nums[i]\n                last_odd_idx += 1\n            \n        return nums
['Python']