2 Ways Solution + VISUAL
\n\n\n\nUsing Stack:\n\nANALYSIS :-\n> Time Complexity :- "BigO(N)"\n> Space Complexity :- "BigO(N)"\n\n\nVisuall Explanation :- \n\n\n\n\n\n\n\nJava\n\nclass S
<hr>\n<hr>\n\n```\nUsing Stack:\n\nANALYSIS :-\n> Time Complexity :- "BigO(N)"\n> Space Complexity :- "BigO(N)"\n```\n\nVisuall Explanation :- \n\n![image](https://assets.leetcode.com/users/images/29086149-f2e4-4791-a733-1193a677825c_1651456477.382558.gif)\n\n\n<hr>\n<hr>\n\n**Java**\n```\nclass Solution {\n    public int[] sortArrayByParity(int[] nums) {\n        Stack<Integer> odd = new Stack<>();\n        Stack<Integer> even = new Stack<>();\n        \n        for(int i = 0; i < nums.length; i++){\n            if(nums[i] % 2 != 0) odd.push(nums[i]);\n            else even.push(nums[i]);\n        }\n        \n        int ans[] = new int[nums.length];\n        int i = 0;\n        while(!even.isEmpty()){\n            ans[i++] = even.pop();\n        }\n        while(!odd.isEmpty()){\n            ans[i++] = odd.pop();\n        }\n        return ans;\n    }\n}\n```\n\n<hr>\n<hr>\n\n```\nIn-Place swap :\n\nANALYSIS :-\n> Time Complexity :- "BigO(N)"\n> Space Complexity :- "BigO(1)"\n```\n\n\n\nVisuall Explanation :- \n\n![image](https://assets.leetcode.com/users/images/1cc1bf1b-6956-4a3b-bd4f-3201a949eece_1651457046.0311866.gif)\n\n<hr>\n<hr>\n\n**Java**\n```\nclass Solution {\n    public int[] sortArrayByParity(int[] nums) {\n        int i = 0;\n        int j = nums.length - 1;\n        \n        while(i < j){\n            if(nums[i] % 2 > nums[j] % 2){\n                int temp = nums[i];\n                nums[i] = nums[j];\n                nums[j] = temp;\n            }\n            if(nums[i] % 2 == 0) i++;\n            if(nums[j] % 2 != 0) j--;\n        }\n        return nums;\n    }\n}\n```
[]