I am simply trying to concatenate a vector to itself but the following code is not working and I am not able to find the issue. If my input vector is {1,2,1}, the o/p I am getting is {1,2,1,1,16842944,1}. Please tell where I am wrong. The output I want is [1,2,1,1,2,1]
vector<int> getConcatenation(vector<int>& nums) {
int size=nums.size();
auto itr=nums.begin();
while(size--)
{
nums.push_back(*itr);
itr++;
}
return nums;
}
Aucun commentaire:
Enregistrer un commentaire