class Solution:
    def sortArrayByParity(self, A: List[int]) -> List[int]:
        i, j = 0, len(A) - 1
        while i < j:
        	if A[i] % 2 == 1 and A[j] % 2 == 0: A[i], A[j] = A[j], A[i]
        	i, j = i + 1 - A[i] % 2, j - A[j] % 2
        return A
class Solution {

    public int[] sortArrayByParity(int[] nums) {
        int i = 0;
        int j = 0;

        while(i < nums.length){
            if(nums[i] % 2 == 1){
                i++;
            }else{
                int temp = nums[i];
                nums[i] = nums[j];
                nums[j] = temp;

                i++;
                j++;
            }
        }

        return nums;
    }
}
Sort Array By Parity
Given an integer array nums, move all the even integers at the beginning of the array followed by all the odd integers.

Return any array that satisfies this condition.

&nbsp;
Example 1:

Input: nums = [3,1,2,4]
Output: [2,4,3,1]
Explanation: The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted.


Example 2:

Input: nums = [0]
Output: [0]


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 5000
	0 &lt;= nums[i] &lt;= 5000


var sortArrayByParity = function(nums) {
  let even = []
  let odd = []
  
  for(let i = 0; i < nums.length; i++){
      (nums[i] % 2 === 0) ? even.push(nums[i]) : odd.push(nums[i])
  }
    
    return [...even, ...odd]
  
    
};
class Solution {
public:
    vector<int> sortArrayByParity(vector<int>& nums)
    {
        vector<int> v;
        vector<int> odd;
        if(nums.size()==1)
        {
            return nums;
        }
        for(auto it : nums)
        {
            if(it%2==0)
            {
                v.push_back(it);
            }
            else
            {
                   odd.push_back(it);
            }
            
        }

        for(auto i : odd)
        {
            v.push_back(i);
        }
        return v;
    }
};