본문 바로가기
Algorithm/BOJ

[백준/BOJ] 1920번 - 수 찾기 (C++)

by shine-jung 2022. 3. 22.
반응형

문제 링크


코드

#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    unordered_set<int> s;
    int n, m, t;
    cin >> n;
    while (n--) {
        cin >> t;
        s.insert(t);
    }
    cin >> m;
    while (m--) {
        cin >> t;
        if (s.find(t) != s.end()) cout << 1 << '\n';
        else cout << 0 << '\n';
    }
}



설명


unordered_set은 Hash 구조이므로 find의 시간복잡도가 O(1)이다.




(주의) 기록용으로 작성한 글입니다. 좋은 코드가 아닐 수 있습니다.

댓글 환영합니다!


반응형

댓글