Algorithm/LeetCode
1929. Concatenation of Array
JunGi Jeong
2023. 3. 30. 16:22
배열 합치기 문제
https://leetcode.com/problems/concatenation-of-array/description/
문제 파악 및 재정의nums라는 정수형 배열이 주어진다.
nums의 2배의 길이를 가진 ans 배열을 반환하라.
ans[i] == nums[i] and ans[i+n] == nums[i]
import java.util.Arrays;
class Solution {
public int[] getConcatenation(int[] nums) {
int n = nums.length;
int[] ans = new int[n*2];
System.arraycopy(nums, 0, ans, 0, n);
System.arraycopy(nums, 0, ans, n, n);
return ans;
}
}