35. Concatenation of Array

EasyArrayArray

Given an integer array nums of length n, return a new array of length 2n formed by appending a copy of nums to the end of itself.

Input: An integer array nums of length n.

Output: Array of length 2n — nums concatenated with itself.

Examples

Example 1
Input: [1,2,1]
Output: [1,2,1,1,2,1]
Explanation: Append nums to itself: [1,2,1] + [1,2,1] = [1,2,1,1,2,1].
Example 2
Input: [1,3,2,1]
Output: [1,3,2,1,1,3,2,1]
Explanation: [1,3,2,1] + [1,3,2,1] = [1,3,2,1,1,3,2,1].
Example 3
Input: [1,2,3]
Output: [1,2,3,1,2,3]
Explanation: [1,2,3] + [1,2,3] = [1,2,3,1,2,3].

Constraints

Asked by

GoogleBloombergAmazonInfosysMicrosoftMeta
Solve this problem in the editor →