프로그래머스 완주하지 못한 선수

조항주·2022년 4월 19일
0

algorithm

목록 보기
30/50
post-thumbnail

문제

https://programmers.co.kr/learn/courses/30/lessons/42576

코드

#include <string>
#include <vector>
#include<map>
#include<iostream>
using namespace std;

string solution(vector<string> participant, vector<string> completion) {

    map<string, int> hash;
    for (auto i : participant) hash[i]++;
    for (auto i : completion) hash[i]--;

    for (auto i : hash) {
        if (i.second == 1)
            return i.first;
    }

}

풀이

해시테이블을 사용해서 풀었습니다 문제에서 완주하지 못한 선수가 1명으로 고정되있다고 써져있기 때문에 출전한 선수를 카운팅하고 완주한 선수를 카운팅해서 한 명의 선수를 리턴하게끔 코드를 짰습니다.

0개의 댓글