Number of Ways to Divide a Long Corridor LeetCode solution in Python

1
class Solution:
2
def numberOfWays(self, corridor):
3
seat, res, plant = 0, 1, 0
4
for i in corridor:
5
if i == "S":
6
seat += 1
7
else:
8
if seat == 2:
9
plant += 1
10
if seat == 3:
11
res = res * (plant + 1) % (10**9 + 7)
12
seat, plant = 1, 0
13
if seat != 2:
14
return 0
15
return res

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0