Simple C++ Solution Beginner Friendly
Intuition\nThe code begins by defining a class called Solution and within this class, there is a method named getConcatenation. This method takes a single param
# Intuition\nThe code begins by defining a class called Solution and within this class, there is a method named getConcatenation. This method takes a single parameter, which is the input vector of integers, denoted as nums.\n\nInside the getConcatenation method, the code calculates the size of the input vector nums and stores this size in a variable named size. This is done to determine the size of the resulting concatenated vector, which will be twice the size of the input vector.\n\nThe code then creates a new vector of integers called arr, with a size of size * 2. This new vector is intended to store the concatenated result.\n\nTo perform the concatenation, the code uses two loops. First, it initializes an integer variable i to 0 and enters a while loop. Within this loop, the code copies the elements from the input vector nums into the arr vector until the index i reaches the size of the input vector. This is effectively a direct copy of the elements from the input vector into the concatenated vector, and it covers the first size elements.\n\nAfter the while loop, the code enters a for loop that iterates over the elements of the input vector nums once more. In this loop, the code copies these elements into the arr vector, starting from where the previous loop left off, which is the index i. This results in a second set of copies of the input vector\'s elements being added to the concatenated vector.\n\nFinally, the method returns the arr vector, which contains the concatenated result. In summary, the code accomplishes the task of creating a new vector where the input vector\'s elements are duplicated, effectively concatenating the input vector with itself, and it does so in a sequential order.\n# Approach\nThe approach of the code can be summarized as follows:\n\n1. *Input Parameter*: The code takes an input vector of integers named `nums` as its sole parameter.\n\n2. *Determine the Size*: It calculates the size of the input vector and stores it in the variable `size`. This step is essential to know how large the resulting concatenated vector should be. The concatenated vector will have a size of `size * 2`.\n\n3. *Initialize Result Vector*: A new vector of integers named `arr` is created with a size of `size * 2`. This vector will be used to store the concatenated result.\n\n4. *Copy Elements with a `while` Loop*: The code enters a `while` loop where it iterates through the elements of the input vector `nums`. Inside the loop, it copies the elements from `nums` into `arr` until the index `i` reaches the size of the input vector. This effectively duplicates the elements from the input vector in the same order at the beginning of the `arr` vector.\n\n5. *Copy Elements with a `for` Loop*: After the `while` loop completes, the code enters a `for` loop that iterates over the elements of the input vector `nums` once more. In this loop, it copies these elements into the `arr` vector, starting from where the `while` loop left off, which is the index `i`. This step adds another set of copies of the input vector\'s elements to the `arr` vector, effectively concatenating the input vector with itself.\n\n6. *Return Result*: Finally, the method returns the `arr` vector, which contains the concatenated result, where the elements from the input vector `nums` are repeated twice in the same order.\n\nOverall, the approach is a straightforward and explicit one, which involves copying the elements of the input vector to the concatenated vector to achieve the desired concatenation effect. The code uses both a `while` loop and a `for` loop to accomplish this, ensuring that the input vector\'s elements are repeated in the same order in the concatenated result.\n# Complexity\n- Time complexity:\nO(size)\n- Space complexity:\nO(size)\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> getConcatenation(vector<int>& nums) {\n        int size=nums.size();\n        vector<int> arr(size*2);\n            int i=0;\n            while(i!=size){\n            arr[i]=nums[i];\n            i++;\n            }\n            for(int j=0;j<size;j++){\n                arr[i]=nums[j];\n                i++;\n            }\n        return arr;\n        \n    }\n};\n\n```\n![7410jl.jpg](https://assets.leetcode.com/users/images/3259140b-bb4e-460b-93df-3e8d3d619fab_1699418793.2211468.jpeg)\n
['C++']