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)


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