[내 풀이]
#include <string>
#include <vector>
using namespace std;
string solution(string my_string, vector<int> indices) {
string answer = "";
for(int i : indices)
{
my_string[i] = 0;
}
for(auto c: my_string)
{
if(c != 0)
{
answer += c;
}
}
return answer;
}
나는 아무 숫자나 공백을 덮어씌워서 그걸 나중에 빼고 넣는 방식으로 풀었지만
[다른 사람 풀이]
#include <bits/stdc++.h>
using namespace std;
string solution(string my_string, vector<int> indices) {
sort(indices.begin(), indices.end(), greater<int>());
for (int i : indices) {
my_string.erase(i, 1);
}
return my_string;
}
erase 함수를 이용해서 푸는 방법도 있다.