SHARE
TWEET

Untitled

a guest Aug 22nd, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<algorithm>
  2. #include<limits.h>
  3. #include<set>
  4. int solution(vector<int> &A) {
  5.     // write your code in C++14 (g++ 6.2.0)
  6.     int size = (int)A.size();
  7.     set<int> res;
  8.     for (int i = 0; i < size; i++) {
  9.         res.insert(A[i]);
  10.     }
  11.    
  12.     //sort(res.begin(), res.end());
  13.     int minV = INT_MAX;
  14.     for (int i = 0; i < (int)res.size(); i++) {
  15.         if (res.count(i + 1) == 0) {
  16.             minV = min(minV, i + 1);
  17.         }
  18.     }
  19.     return minV == INT_MAX ? size + 1 : minV;
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top