Advertisement
jasonpogi1669

Find the MEX with Sets using C++

Jul 25th, 2021
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     cin >> n;
  8.     set<int> s;
  9.     for (int i = 0; i < n; i++) {
  10.         int x;
  11.         cin >> x;
  12.         s.insert(x);
  13.     }
  14.     int MEX = 1;
  15.     while (s.count(MEX)) {
  16.         MEX++;
  17.     }
  18.     cout << MEX << '\n';
  19.     return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement