문제를 이해하고 있다면 바로 풀이를 보면 됨
전체 코드로 바로 넘어가도 됨
마음대로 번역해서 오역이 있을 수 있음
길이가 n인 정수 배열 nums가 주어졌을때, 길이가 2n인 배열 ans를 만들고 싶다. ans[i] == nums[i]이고 ans[i + n] == nums[i]에 대해 0 <= i < n(0부터 시작)이다.
구체적으로, ans는 2개의 배열 nums를 이어 붙인 것이다.
배열 ans를 반환해라.
#1
Input: nums = [1, 2, 1]
Output: [1, 2, 1, 2, 1]
#2
Input: nums = [1,3, 2, 1]
Output: [1, 3, 2, 1, 3, 2, 1]
class Solution {
public int[] getConcatenation(int[] nums) {
int n = nums.length;
int[] ans = new int[n * 2];
for(int i = 0; i < n * 2; i++){
ans[i] = nums[i % n];
}
return ans;
}
}