Skip to content

Commit

Permalink
Create 5974.Number-of-Ways-to-Divide-a-Long-Corridor.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored Jan 22, 2022
1 parent a0c9ea9 commit 5bafa88
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using LL = long long;
LL M = 1e9+7;
class Solution {
public:
int numberOfWays(string corridor)
{
int n = corridor.size();

vector<int>seats;
for (int i=0; i<n; i++)
{
if (corridor[i]=='S')
seats.push_back(i);
}

if (seats.size() == 0) return 0;
if (seats.size() == 2) return 1;
if (seats.size() % 2 !=0) return 0;

LL ret = 1;
for (int i=2; i+2<=seats.size(); i+=2)
{
int a = seats[i]-seats[i-1];
ret *= (LL)a;
ret %= M;
}
return ret;
}
};

0 comments on commit 5bafa88

Please sign in to comment.