본문 바로가기
IT/알고리즘

10] Leetcode 1389. Create Target Array in the Given Order

by 깻잎쌈 2020. 6. 23.
반응형

 

 

Create Target Array in the Given Order - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

int 벡터에 원하는 위치에 숫자를 넣는 문제.

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

 앞에서부터 index번째에 nums를 삽입한다.

ans.insert(ans.begin()+index, nums);

 

 

 

혼자 연구하는 C/C++ by WinApi

40-1-나.삽입과 삭제 요소의 집합을 관리하는 컨테이너에서 삽입과 삭제는 가장 기본적인 동작이다. 각 컨테이너별로 내부적인 구조가 다르기 때문에 삽입, 삭제 방식도 컨테이너별로 다를 수밖�

soen.kr

 

 

vector insert() function in C++ STL - GeeksforGeeks

A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

www.geeksforgeeks.org

 

반응형

댓글