1929. Concatenation of Array

Solution

class Solution {
public:
    vector<int> getConcatenation(vector<int>& nums) {
        vector<int> result(nums.size() * 2);
        
        for (int i = 0; i < nums.size(); i++) {
            result[i] = nums[i];
            result[i + nums.size()] = nums[i];
        }
        
        return result;
    }
};

Complexity

  • Time Complexity: O(N), where N is the size of nums.
  • Space Complexity: O(2N), where N is the size of nums.

All Solutions