반응형
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);
반응형
'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 |
댓글