[코테 풀이] Concatenation of Array

시내·2024년 6월 10일
0

Q_1929) Concatenation of Array

출처 : https://leetcode.com/problems/concatenation-of-array/

Given an integer array nums of length n, you want to create an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n (0-indexed).

Specifically, ans is the concatenation of two nums arrays.

Return the array ans.

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

0개의 댓글

관련 채용 정보