Make Unreal REAL.
article thumbnail
Level 0. 글자 지우기

 

 

indices의 원소 범위가 주어지지 않아. 배열 대신 unordered_map을 사용했다.

 

문자열을 붙이게 되면 메모리 재할당이 빈번하게 발생하므로, 미리 크기를 할당해놓고 사용했다.

 

#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

string solution(string my_string, vector<int> indices)
{
    size_t len = my_string.length(), size = indices.size();
    string answer(len - size, '\0');
    unordered_map<int, bool> umap;
    
    for (int index : indices)
        umap[index] = true;

    for (int i = 0, j = 0; j < answer.length(); ++i)
        if (umap[i] == false)
            answer[j++] = my_string[i];

    return answer;
}
profile

Make Unreal REAL.

@diesuki4

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!

검색 태그