Two pointers technique (Python, O(n) time / O(1) space)
Hi LeetCoders \uD83D\uDC4B\nHere is my simple and clean solution to this problem.\n\nCode:\n\nclass Solution:\n    def sortArrayByParity(self, nums: List[int]) 
Hi LeetCoders \uD83D\uDC4B\nHere is my simple and clean solution to this problem.\n\n**Code:**\n```\nclass Solution:\n    def sortArrayByParity(self, nums: List[int]) -> List[int]:\n        slow = fast = 0\n        while fast < len(nums):\n            if not (nums[fast] % 2):\n                nums[slow], nums[fast] = nums[fast], nums[slow]\n\n            if not (nums[slow] % 2):\n                slow += 1\n\n            fast += 1\n\n        return nums\n```\n\n**Algorithm complexity:**\n*Time complexity: O(n)*\n*Space complexity: O(1)*\n\n**This technique can also be applied to:**\n283. Move Zeroes - [**Two pointers technique (Python, O(n) time / O(1) space)**](https://leetcode.com/problems/move-zeroes/discuss/562911/Two-pointers-technique-(Python-O(n)-time-O(1)-space))\n\nIf you like my solution, I will really appreciate your upvoting. It will help other python-developers to find it faster. And as always, I hope you learned something and wish you an enjoyable time on LeetCode. \uD83D\uDE0A
['Two Pointers', 'Python3']