leetcode

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

1358.cpp (393B)


      1 class Solution {
      2   public:
      3     int numberOfSubstrings(const string &s) {
      4         int st[3] = {0}, count = 0, res = 0, left = 0;
      5         for (int i = 0; i < s.size(); i++) {
      6             if (!st[s[i] - 'a']++) count++;
      7             while (count == 3) {
      8                 res += s.size() - i;
      9                 if (!--st[s[left++] - 'a']) count--;
     10             }
     11         }
     12         return res;
     13     }
     14 };