Skip to content

Latest commit

 

History

History
68 lines (52 loc) · 1.5 KB

_1929. Concatenation of Array.md

File metadata and controls

68 lines (52 loc) · 1.5 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 03, 2024

Last updated : July 01, 2024


Related Topics : Array, Simulation

Acceptance Rate : 90.17 %


Solutions

C

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* getConcatenation(int* nums, int numsSize, int* returnSize) {
    int* output = (int*) malloc(sizeof(int) * 2 * numsSize);
    *returnSize = 2 * numsSize;

    for (int i = 0; i < numsSize; i++) {
        output[i] = nums[i];
        output[i + numsSize] = nums[i];
    }

    return output;
}

Java

class Solution {
    public int[] getConcatenation(int[] nums) {
        int[] output = new int[nums.length * 2];

        for (int i = 0; i < nums.length; i++) {
            output[i] = output[i + nums.length] = nums[i];
        }

        return output;
    }
}

Python

class Solution:
    def getConcatenation(self, nums: List[int]) -> List[int]:
        return nums + nums