leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2260.cpp (405B)


      1 class Solution {
      2   public:
      3     int minimumCardPickup(const vector<int> &cards) const {
      4         static int pos[1000001];
      5         int res = INT_MAX;
      6 
      7         memset(pos, 0xFF, sizeof(pos));
      8         for (int i = 0; i < size(cards); i++) {
      9             if (pos[cards[i]] != -1) res = min(res, i - pos[cards[i]]);
     10             pos[cards[i]] = i;
     11         }
     12 
     13         return res != INT_MAX ? res + 1 : -1;
     14     }
     15 };