반응형
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
반응형
'IT > 알고리즘' 카테고리의 다른 글
12] Leetcode 1486. XOR Operation in an Array (0) | 2020.06.24 |
---|---|
11] Leetcode 1295. Find Numbers with Even Number of Digits (0) | 2020.06.24 |
9] Leetcode 1281. Subtract the Product and Sum of Digits of an Integer (0) | 2020.06.22 |
8] Leetcode 1313. Decompress Run-Length Encoded List (0) | 2020.06.21 |
7] Leetcode 1365. How Many Numbers Are Smaller Than the Current Number (0) | 2020.06.21 |
댓글