1929. Concatenation of Array
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 03, 2024
Last updated : July 01, 2024
Related Topics : Array, Simulation
Acceptance Rate : 90.17 %
/**
* 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;
}
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;
}
}
class Solution:
def getConcatenation(self, nums: List[int]) -> List[int]:
return nums + nums