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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
string solution(vector<string> participant, vector<string> completion) 
{
    int iSize = participant.size();
    sort(participant.begin(), participant.end());
    sort(completion.begin(), completion.end());
 
    for(int i = 0 ; i < iSize ; i++)
    {
        //if(participant[i] != completion[i]) //정석 풀이
            //return participant[i];
        if(participant[i] == completion[i]) //내 방식 풀이
            continue;
        else
            return participant[i];
    }
 
    return string();
}
 

algorithm 헤더를 사용해 벡터를 빠르게 정렬할 수 있음.

 

같은 string 비교는 굳이 compare가 아니라 연산자 오버로딩된 것으로도 가능함

 

 

+ Recent posts