https://school.programmers.co.kr/learn/courses/30/lessons/120896
map을 이용하여 글자 하나하나 map에 추가한다. 중복되면 value값을 ++한다.
다 추가 한 뒤 value가 1이면 해당 문자를 answer에 넣어준다
#include <string>
#include <vector>
#include <map>
using namespace std;
string solution(string s) {
string answer = "";
map<char,int> m;
for(const auto v : s)
{
m[v]++;
}
for(const auto& v : m)
{
if(v.second == 1)
{
answer.push_back(v.first);
}
}
return answer;
}
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
string solution(string s) {
string answer = "";
sort(s.begin(),s.end());
map<char,int> m;
for(auto ch : s)
{
m[ch]++;
}
for(auto it= m.begin(); it != m.end(); it++)
{
if(it->second == 1)
answer.push_back(it->first);
}
sort(answer.begin(),answer.end());
return answer;
}
map의 for문을 돌릴 때 iterator를 사용하였다.