leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE |

commit6d471b97cd0e07068ecb020bcfda401cbc704d72
parentde45cf25b94c02c2f225e8b46103db0361147a4a
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateTue, 28 Nov 2023 20:45:07 +0000

Daily Problem

Diffstat:
AProblems/2147.cpp|++++++++++++++++++++
MREADME.md|+

2 files changed, 21 insertions(+), 0 deletions(-)


diff --git a/Problems/2147.cpp b/Problems/2147.cpp

@@ -0,0 +1,20 @@

class Solution {
public:
int numberOfWays(const string &corridor) const {
int total = 0, crnt = 0, start = 0;
long res = 1;
for (int i = 0; i < corridor.size(); i++) {
if (corridor[i] != 'S') continue;
if (crnt == 1) start = i;
if (crnt == 2) {
if (start) {
res = (res * (i - start)) % static_cast<int>(1E9 + 7);
}
start = crnt = 0;
}
crnt++, total++;
}
return !total || total % 2 ? 0 : res;
}
};

diff --git a/README.md b/README.md

@@ -799,6 +799,7 @@ for solving problems.

| 2131 | Medium | [Longest Palindrome by Concatenating Two Letter Words](Problems/2131.cpp) |
| 2140 | Medium | [Solving Questions With Brainpower](Problems/2140.cpp) |
| 2141 | Hard | [Maximum Running Time of N Computers](Problems/2141.cpp) |
| 2147 | Hard | [Number of Ways to Divide a Long Corridor](Problems/2147.cpp) |
| 2149 | Medium | [Rearrange Array Elements by Sign](Problems/2149.cpp) |
| 2150 | Medium | [Find All Lonely Numbers in the Array](Problems/2150.cpp) |
| 2155 | Medium | [All Divisions With the Highest Score of a Binary Array](Problems/2155.cpp) |