Concatenation of Array

LeetCode

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.

1def getConcatenation(nums: List[int]) -> List[int]:
2 n = len(nums)
3 ans = [0] * (2 * n)
4 for i in range(n):
5 ans[i] = nums[i]
6 ans[i + n] = nums[i]
7 return ans
i
0
0
0
1
0
2
0
3
0
4
0
5
0
6
0
7
n=4
nums=[5, 1, 9, 3]
Step 1 / 6
Step 1:
Allocate ans with length 2n, then fill ans[i] and ans[i+n] in one pass.
Pointers: i=0
Focus: default
n=4