leetcode

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

2147.cpp (576B)


      1 class Solution {
      2   public:
      3     int numberOfWays(const string &corridor) const {
      4         int total = 0, crnt = 0, start = 0;
      5         long res = 1;
      6         for (int i = 0; i < corridor.size(); i++) {
      7             if (corridor[i] != 'S') continue;
      8             if (crnt == 1) start = i;
      9             if (crnt == 2) {
     10                 if (start) {
     11                     res = (res * (i - start)) % static_cast<int>(1E9 + 7);
     12                 }
     13                 start = crnt = 0;
     14             }
     15             crnt++, total++;
     16         }
     17 
     18         return !total || total % 2 ? 0 : res;
     19     }
     20 };