328. 완주하지 못한 선수

아현·2021년 11월 11일
0

Algorithm

목록 보기
352/400
post-custom-banner

프로그래머스





1. Python



from collections import Counter

def solution(participant, completion):
    answer = ''
    p = Counter(participant)
    c = Counter(completion)
    
    for i in participant:
        if(p[i] != c[i]):
            answer += i
            break
    
    return answer
    
  



2. C++



#include <string>
#include <vector>
#include <algorithm>

using namespace std;

string solution(vector<string> participant, vector<string> completion) {
    string answer = "";
    sort(participant.begin(), participant.end());
    sort(completion.begin(), completion.end());
    for(int i=0;i<completion.size();i++)
    {
        if(participant[i] != completion[i])
            return participant[i];
    }
    return participant[participant.size() - 1];
   
}



3. JavaScript



function solution(participant, completion) {
    participant.sort();
    completion.sort();
    for(let i = 0; i < completion.length; i++){
        if(participant[i] != completion[i])
            return participant[i]
    }
    
    return participant[participant.length -1]
}

profile
For the sake of someone who studies computer science
post-custom-banner

0개의 댓글