개발/CodingTest

LeetCode - Shuffle the array

Lumasca 2020. 6. 26. 12:07
class Solution {
    public int[] shuffle(int[] nums, int n) {
        int len = nums.length;
        int[] res = new int[len];
        int resIndex = 0;
        for(int i=0; i < len/2; i++){//배열 중간까지만 진행
            res[resIndex] = nums[i];//첫번째값
            res[++resIndex] = nums[i+n];//두번째값은 n만큼 더한 위치
            resIndex++;
        }
        return res;
    }
}