Posted on

Description

Submission

class Solution {
public:
    vector<int> createTargetArray(vector<int>& nums, vector<int>& index) {
        list<int> l;
        int n = nums.size();
        for(int i = 0; i < n; ++i) {
            auto it = l.begin();
            for(int j = 0; j < index[i]; ++j, ++it);
            l.insert(it, nums[i]);
        }
        return {l.begin(), l.end()};
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *