LC 1389. Create Target Array in the Given Order

Nilanjan Deb · April 5, 2020

This is my CPP solution.

class Solution {
public:
    vector<int> createTargetArray(vector<int>& nums, vector<int>& index) {
        int n = nums.size();
        vector<int>target;
        target.push_back(nums[0]);
        for(int i=1;i<n;i++){
            target.insert(target.begin()+index[i],nums[i]);
        }
        return target;
    }
};


Dicussion Forum