Number of Ways to Divide a Long Corridor LeetCode solution in C++

1
class Solution {
2
public:
3
int numberOfWays(string corridor) {
4
// Store 1000000007 in a variable for convenience
5
const int MOD = 1e9 + 7;
6

7
// Initial values of three variables
8
int zero = 0;
9
int one = 0;
10
int two = 1;
11

12
// Compute using derived equations
13
for (char thing : corridor) {
14
if (thing == 'S') {
15
zero = one;
16
swap(one, two);
17
} else {
18
two = (two + zero) % MOD;
19
}
20
}
21

22
// Return the result
23
return zero;
24
}
25
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0