[C++] Simple Solutions || Straight Forward Solutions || Different Approaches
SolutionTo solve the problem, we first determine the number of elements in the input vector. Next, we create a new vector that is twice as large to accommodate
# Solution

To solve the problem, we first determine the number of elements in the input vector. Next, we create a new vector that is twice as large to accommodate the combined result. Finally, we copy each element from the input vector into the new vector, placing them in the correct positions to achieve the desired concatenation.


**Time Complexity: O(N)**
**Space Complaexity: O(N)**

1. Rewriting the Statement Inside the Loop

``` C++ []
#include <vector>

/**
 * @brief Solution class to concatenate a vector with itself.
 */
class Solution {
public:
    /**
     * @brief Concatenates the given vector with itself.
     * @param nums The input vector of integers.
     * @return A new vector that is the concatenation of nums with itself.
     */
    std::vector<int> getConcatenation(std::vector<int>& nums) {
        int n = nums.size();
        std::vector<int> ans(2 * n);
        for (int i = 0; i < n; i++)
            ans[i + n] = ans[i] = nums[i];
        return ans;
    }
};
```
2. Avoiding nums.size() in the Loop

```C++ []
#include <vector>

/**
 * @brief Solution class to concatenate a vector with itself.
 */
class Solution {
public:
    /**
     * @brief Concatenates the given vector with itself.
     * @param nums The input vector of integers.
     * @return A new vector that is the concatenation of nums with itself.
     */
    std::vector<int> getConcatenation(std::vector<int>& nums) {
        int n = nums.size();
        for (int i = 0; i < n; i++)
            nums.push_back(nums[i]);
        return nums;
    }
};
```

3. Using insert Method

```C++ []
#include <vector>

/**
 * @brief Solution class to concatenate a vector with itself.
 */
class Solution {
public:
    /**
     * @brief Concatenates the given vector with itself.
     * @param nums The input vector of integers.
     * @return A new vector that is the concatenation of nums with itself.
     */
    std::vector<int> getConcatenation(std::vector<int>& nums) {
        nums.insert(nums.end(), nums.begin(), nums.end());
        return nums;
    }
};
```
4. Resizing the Vector

```C++ []
#include <vector>

/**
 * @brief Solution class to concatenate a vector with itself.
 */
class Solution {
public:
    /**
     * @brief Concatenates the given vector with itself.
     * @param nums The input vector of integers.
     * @return A new vector that is the concatenation of nums with itself.
     */
    std::vector<int> getConcatenation(std::vector<int>& nums) {
        int n = nums.size();
        nums.resize(2 * n);
        for (int i = 0; i < n; i++)
            nums[n + i] = nums[i];
        return nums;
    }
};
```
5. Using copy_n Method

```C++ []
#include <vector>
#include <algorithm>

/**
 * @brief Solution class to concatenate a vector with itself.
 */
class Solution {
public:
    /**
     * @brief Concatenates the given vector with itself.
     * @param nums The input vector of integers.
     * @return A new vector that is the concatenation of nums with itself.
     */
    std::vector<int> getConcatenation(std::vector<int>& nums) {
        int n = nums.size();
        std::vector<int> res(n * 2);
        std::copy_n(nums.begin(), n, res.begin());
        std::copy_n(nums.begin(), n, res.begin() + n);
        return res;
    }
};
```
6. Using reserve and insert Methods

```C++ []
#include <vector>

/**
 * @brief Solution class to concatenate a vector with itself.
 */
class Solution {
public:
    /**
     * @brief Concatenates the given vector with itself.
     * @param nums The input vector of integers.
     * @return A new vector that is the concatenation of nums with itself.
     */
    std::vector<int> getConcatenation(std::vector<int>& nums) {
        std::vector<int> res;
        res.reserve(nums.size() * 2);
        res.insert(res.end(), nums.begin(), nums.end());
        res.insert(res.end(), nums.begin(), nums.end());
        return res;
    }
};
```
['Array', 'Simulation', 'C++']