코린이의 소소한 공부노트

[LeetCode/Easy] 1470. Shuffle the Array 본문

코딩테스트 풀이/JAVA

[LeetCode/Easy] 1470. Shuffle the Array

무지맘 2022. 12. 26. 12:24

1. Input

1) int 배열 nums

2) 정수 n

3) nums의 요소는 [x1, x2, ..., xn, y1, y2, ..., yn]2n개로 이루어져 있다.

 

2. Output

1) nums의 배열을 [x1, y1, x2, y2, ..., xn, yn]의 형태로 재배열한 결과

 

3. Constraint

1) 1 <= n <= 500

2) nums.length == 2n

3) 1 <= nums[i] <= 10^3

 

4. Example

Input: nums = [1,1,2,2], n = 2 -> Output: [1,2,1,2]

 

5. Code

1) 첫 코드(2022/06/02)

int[] result = new int[2*n];
for(int i=0 ; i<n ; i++){
    result[2*i] = nums[i];
    result[2*i+1] = nums[n+i];
}
return result;