AlgoLounge

Concatenation of Array

medium

You are given an integer array nums of length n. 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.

Examples

Example 1

Input:  nums = [1,4,1,2]
Output: [1,4,1,2,1,4,1,2]

Example 2

Input:  nums = [22,21,20,1]
Output: [22,21,20,1,22,21,20,1]

Constraints

  • 1 <= nums.length <= 1000
  • 1 <= nums[i] <= 1000
TypeScript
Loading editor…
List of test cases (4)
Case 1
nums = [1,4,1,2]
Case 2
nums = [22,21,20,1]
Case 3
nums = [1]
Case 4
nums = [1,2,3]