Advertisement
DeepRest

Number of Ways to Divide a Long Corridor

Jan 23rd, 2022
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. class Solution:
  2.     def numberOfWays(self, corridor: str) -> int:
  3.         res = 1
  4.         cnt = 0
  5.         temp = 1
  6.         for i in corridor:
  7.             if cnt == 2 and i == 'P':
  8.                 temp += 1
  9.             elif cnt == 2 and i == 'S':
  10.                 res *= temp
  11.                 temp = 1
  12.                 cnt = 1
  13.             else:
  14.                 cnt += int(i=='S')
  15.         if cnt == 2:
  16.             return res%int(1e9+7)
  17.         return 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement