‡ CODING TEST STUDY ‡/º 프로그래머스

프로그래머스 [Lv1] | 완주하지 못한 선수

Trudy | 송연 2023. 7. 28. 16:10
 
#include <string>
#include <vector>

using namespace std;

int find(vector<string> participant, string str){
    for(int i=0; i<participant.size(); i++){
        if(participant[i] == str) return i;
    }
    return -1;
}

string solution(vector<string> participant, vector<string> completion) {
    vector<string> p = participant; 
    for(int i=0; i<completion.size();i++) p[find(p,completion[i])] = "0";
    
    for(int i=0; i<p.size(); i++){
        if(p[i] != "0") return p[i];
    }
}

이렇게 코드를 짰더니 테스트에 통과돼서 제출했더니..

 

 

​시간 초과가 처음으로 떠서 불필요한 for문이 있나 확인했는 데 못찾음

 

[프로그래머스] 완주하지 못한 선수 / C++ (map) (tistory.com)

결국 구글링을 해보았는데 HashMap, Map을 많이 쓰더라.

윗 글에서 Map 쓴거는 진짜 혁명적이다!! 저번 포스팅에서 Set, Map에 대해서 정리하고 공부했는데 이렇게 쓸 수 있다고 생각을 못했다