leetcode

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

commit e184e2cf96e080d0efe13efd05fead11e3da531f
parent a6b81c8329e1bb388ca0ac282047064f48632375
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sat, 30 Mar 2024 18:55:13 +0000

1 Random Problem

Diffstat:
AProblems/3101.cpp | 13+++++++++++++
MREADME.md | 1+
2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/Problems/3101.cpp b/Problems/3101.cpp @@ -0,0 +1,13 @@ +class Solution { + public: + long long countAlternatingSubarrays(const vector<int> &nums) const { + long long res = 1; + + for (int i = 1, cnt = 1; i < size(nums); i++) { + cnt = nums[i] == nums[i - 1] ? 1 : cnt + 1; + res += cnt; + } + + return res; + } +}; diff --git a/README.md b/README.md @@ -1181,3 +1181,4 @@ for solving problems. | 3034 | Medium | [Number of Subarrays That Match a Pattern I](Problems/3034.cpp) | | 3039 | Medium | [Apply Operations to Make String Empty](Problems/3039.cpp) | | 3070 | Medium | [Count Submatrices with Top-Left Element and Sum Less Than k](Problems/3070.cpp) | +| 3101 | Medium | [Count Alternating Subarrays](Problems/3101.cpp) |