[LeetCode] Concatenate Array With Reverse

3925. Concatenate Array With Reverse

You are given an integer array nums of length n.

Construct a new array ans of length 2 * n such that the first n elements are the same as nums, and the next n elements are the elements of nums in reverse order.

Formally, for 0 <= i <= n - 1:

  • ans[i] = nums[i]
  • ans[i + n] = nums[n - i - 1]

Return an integer array ans.

1
2
3
4
5
6
7
class Solution {
public:
vector<int> concatWithReverse(vector<int>& nums) {
for(int i = nums.size() - 1; i >= 0; i--) nums.push_back(nums[i]);
return nums;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2026/09/04/PS/LeetCode/concatenate-array-with-reverse/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.