Beat 99.91% [ Help you how to think about situation ]
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int[] sortArrayByParity(int[] nums) {\n        int[] ans = new int[nums.length];\n        int k=0;\n        int k2=nums.length-1;\n        for(int i=0;i<nums.length;i++){\n            if(nums[i]%2==0) ans[k++]=nums[i];\n            else ans[k2--]=nums[i];\n        }\n        return ans;\n    }\n}\n```
['Java']