🔥🔥 Python & Java || Easy & Simple Two Pointers || Intuition Explained🔥🔥
Intuition / Approach\n- Maintain two pointers; even = 0  and  odd = n-1\n- All indices less than \'even\' will have even numbers in the array \n- All indices hi
# Intuition / Approach\n- Maintain two pointers; even = 0  and  odd = n-1\n- All indices less than \'even\' will have even numbers in the array \n- All indices higher than \'odd\' will have odd numbers in the array \n- Keep shifting pointers \'even\' & \'odd\' based on above condition\n- When \'even\' & \'odd\' crosses each other, array will be arranged \n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n\n# Python Code\n```\nclass Solution:\n    def sortArrayByParity(self, nums: List[int]) -> List[int]:\n        even, odd = 0, len(nums) - 1\n        while even < odd:\n            if nums[even] % 2 == 0:\n                even += 1\n            elif nums[odd] % 2 == 1:\n                odd -= 1\n            else:\n                nums[even], nums[odd] = nums[odd], nums[even]\n        return nums\n        \n```\n\n# Java Code\n```\nclass Solution {\n    public int[] sortArrayByParity(int[] nums) {\n        int n = nums.length;\n        int even = 0, odd = n - 1;\n\n        while (even < odd){\n            if (nums[even] % 2 == 0)\n                even++;\n            else if (nums[odd] % 2 == 1)\n               odd--;\n            else{\n                int temp = nums[even];\n                nums[even] = nums[odd];\n                nums[odd] = temp;\n            }\n        }\n        return nums;\n    }\n}\n```
['Two Pointers', 'Java', 'Python3']