Skip to main content
Back to problems
Leetcode
Easy
Arrays
Concatenation Of Array

Build a new array by appending the input array to itself once.

Acceptance 100%
Problem Statement

Problem

Given an integer array nums, construct a new array ans such that:

  • ans.length = 2 * nums.length
  • for every valid index i, ans[i] = nums[i]
  • for every valid index i, ans[i + nums.length] = nums[i]

In other words, return the concatenation of the array with itself.

Input Format

  • A list of integers nums.

Output Format

  • A list of integers representing nums followed by nums again.

Constraints

  • 0 <= nums.length
  • The array may contain any integers.
  • Return a new array; do not modify the original input in place unless explicitly allowed by the platform.

Hints

  • The second half is identical to the first half.
  • You can build the result directly using a single pass or by copying the array twice.

Input Format

  • nums: integer array

Output Format

  • Integer array of length 2 * nums.length

Constraints

  • Return the input array concatenated with itself.
  • Keep the solution linear in the size of the input.
Examples
Sample cases returned by the problem API.

Example 1

Input

nums = [1,2,1]

Output

[1,2,1,1,2,1]

Explanation

The array is appended to itself once.

Example 2

Input

nums = [0,3,5,7]

Output

[0,3,5,7,0,3,5,7]

Explanation

Copy the full array in order, then repeat the same sequence.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.