leetcode

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

1759.cpp (371B)


      1 class Solution {
      2     static const int MOD = 1E9 + 7;
      3 
      4   public:
      5     int countHomogenous(const string &s) const {
      6         int res = 1, count = 1;
      7         for (int i = 1; i < s.size(); i++) {
      8             if (s[i] != s[i - 1])
      9                 count = 1;
     10             else
     11                 count++;
     12             res = (res + count) % MOD;
     13         }
     14         return res;
     15     }
     16 };