[코테 풀이] Shuffle the Array

시내·2024년 6월 10일
0

Q_1470) Shuffle the Array

출처 : https://leetcode.com/problems/shuffle-the-array/

Given the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn].

Return the array in the form [x1,y1,x2,y2,...,xn,yn].

class Solution {
    public int[] shuffle(int[] nums, int n) {
        int[] res = new int[nums.length];
        int index = 0;
        for (int i = 0; i < n; i++) {
            res[index++] = nums[i];
            res[index++] = nums[i + n];
        }
        return res; 
    }
}
profile
contact 📨 ksw08215@gmail.com

0개의 댓글