leetcode

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

1624.cpp (448B)


      1 class Solution {
      2   public:
      3     int maxLengthBetweenEqualCharacters(const string &s) const {
      4         static int index[27];
      5         int res = -1;
      6         memset(index, 0xFF, sizeof(index));
      7         for (int i = 0; i < s.size(); i++) {
      8             const int idx = s[i] & 0x1F;
      9             if (index[idx] == -1)
     10                 index[idx] = i;
     11             else
     12                 res = max(res, i - index[idx] - 1);
     13         }
     14         return res;
     15     }
     16 };