Unknown's avatar

1470. Shuffle the Array

1470. Shuffle the Array

class Solution {
    public int[] shuffle(int[] nums, int n) {
        int[] out = new int[nums.length];
        int x =0;
        int y = nums.length/2;
        for(int i = 0; i < nums.length; i++){
            if(i % 2 == 0){
                out[i] = nums[x];
                x++;
            }else{
                out[i] = nums[y];
                y++;
            }
        }
        return out;
    }
}

Leave a comment