Leetcode

Concatenation of Array

  • Time:O(n)
  • Space:O(n)

C++

class Solution {
 public:
  vector<int> getConcatenation(vector<int>& nums) {
    const int n = nums.size();

    for (int i = 0; i < n; ++i)
      nums.push_back(nums[i]);

    return nums;
  }
};

JAVA

class Solution {
  public int[] getConcatenation(int[] nums) {
    final int n = nums.length;

    int[] ans = new int[n * 2];

    for (int i = 0; i < n; ++i)
      ans[i] = ans[i + n] = nums[i];

    return ans;
  }
}

Python

class Solution:
  def getConcatenation(self, nums: List[int]) -> List[int]:
    return nums * 2