[Codility] FirstUnique
[Codility] FirstUnique
https://app.codility.com/programmers/trainings/4/first_unique/start/
Codility
Your browser is not supported Please, update your browser or switch to a different one. Learn more about what browsers are supported
app.codility.com

해결전략
정렬 sort
정답 코드
#include <queue>
#include <map>
#include <algorithm>
int solution(vector<int> &A) {
    
    int n = A.size();
    queue<int> Q;
    map<int, int> myMap;
    for(int i = 0; i < n; i++){
        Q.push(A[i]);
        if(myMap.find(A[i]) != myMap.end()){
            myMap[A[i]]++;
        }
        else{
            myMap[A[i]] = 1;
        }
    }
    int answer = -1;
    while(!Q.empty())
    {
        int front = Q.front();
        Q.pop();
        if(myMap[front] == 1){
            answer = front;
            break;
        }
    }
    return answer;
}
'⭐ 코딩테스트 > Codility' 카테고리의 다른 글
| [Codility] Array Inversion Count (0) | 2024.02.18 | 
|---|---|
| [Codility] Tree Height (0) | 2024.02.18 | 
| [Codility] Tree Longest Zigzag (0) | 2024.02.18 | 
| [Codility] The Matrix (0) | 2024.02.17 | 
| [Codility] MaxNonoverlappingSegments (1) | 2024.02.06 | 
댓글
이 글 공유하기
다른 글
- 
[Codility] Tree Height[Codility] Tree Height2024.02.18
- 
[Codility] Tree Longest Zigzag[Codility] Tree Longest Zigzag2024.02.18
- 
[Codility] The Matrix[Codility] The Matrix2024.02.17
- 
[Codility] MaxNonoverlappingSegments[Codility] MaxNonoverlappingSegments2024.02.06