leetcode

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

commit 21ae357291d53efd4ef88bb4672af5dc2d2ceecf
parent 3b9b684db3c3ef2f0eed7afd90219acfd157fc7c
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Thu,  9 Nov 2023 18:32:26 +0000

Daily Problem

Diffstat:
AProblems/1759.cpp | 16++++++++++++++++
MREADME.md | 1+
2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/Problems/1759.cpp b/Problems/1759.cpp @@ -0,0 +1,16 @@ +class Solution { + static const int MOD = 1E9 + 7; + + public: + int countHomogenous(const string &s) const { + int res = 1, count = 1; + for (int i = 1; i < s.size(); i++) { + if (s[i] != s[i - 1]) + count = 1; + else + count++; + res = (res + count) % MOD; + } + return res; + } +}; diff --git a/README.md b/README.md @@ -718,6 +718,7 @@ for solving problems. | 1743 | Medium | [Restore the Array From Adjacent Pairs](Problems/1743.cpp) | | 1751 | Hard | [Maximum Number of Events That Can Be Attended II](Problems/1751.cpp) | | 1753 | Medium | [Maximum Score From Removing Stones](Problems/1753.cpp) | +| 1759 | Medium | [Count Number of Homogenous Substrings](Problems/1759.cpp) | | 1760 | Medium | [Minimum Limit of Balls in a Bag](Problems/1760.cpp) | | 1765 | Medium | [Map of Highest Peak](Problems/1765.cpp) | | 1768 | Easy | [Merge Strings Alternately](Problems/1768.cpp) |