문제
소스코드
#include <string>
#include <vector>
#include<set>
using namespace std;
string solution(vector<string> participant, vector<string> completion) {
multiset<string> set_partic;
multiset<string> set_compl;
string answer = "";
for (auto& iter : participant) {
set_partic.insert(iter);
}
for (auto& iter : completion) {
set_compl.insert(iter);
}
for (auto& iter : set_partic) {
if (set_compl.count(iter)) {
auto par_result = set_partic.count(iter);
auto compl_result = set_compl.count(iter);
if (par_result - compl_result != 0) {
return iter;
}
}
else
return iter;
}
}
후기
예전에 풀었던 문제지만 풀었던 문제 중 가장 해시다운 문제였다. 두 개의 Set을 비교해서 값이 있는지 없는지를 판단하였다. 기억으로는 효율성 테스트에서 꽤 애먹은걸로 기억한다.
출처 및 레퍼런스
문제 링크:https://programmers.co.kr/learn/courses/30/lessons/42576
'온라인 코딩 > 연관 컨테이너(associate container)' 카테고리의 다른 글
[백준] 11728번 배열 합치기 (0) | 2021.02.17 |
---|---|
[프로그래머스] 이중우선순위큐 (0) | 2020.10.02 |
[백준] 10816번 숫자 카드 2 (0) | 2020.07.03 |
[프로그래머스] 전화번호 목록 (0) | 2020.02.19 |