leetcode

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

commit b217fbac194589a7e335e0fd4a3f5af91bee7f7d
parent f7d99782c47ebfb547844991de02651a8f586857
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Fri,  5 May 2023 11:16:44 +0200

Daily Problem

Diffstat:
AProblems/1456.cpp | 21+++++++++++++++++++++
R1639.cpp -> Problems/1639.cpp | 0
MREADME.md | 1+
3 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/Problems/1456.cpp b/Problems/1456.cpp @@ -0,0 +1,21 @@ +class Solution { + bool isVowel(char c) { + return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'; + } + +public: + int maxVowels(string s, int k) { + int i, cnt = 0; + for (i = 0; i < k; i++) + if (isVowel(s[i])) cnt++; + + int maxi = cnt; + for (; i < s.size(); i++) { + if (isVowel(s[i - k])) cnt--; + if (isVowel(s[i])) cnt++; + maxi = max(maxi, cnt); + } + + return maxi; + } +}; diff --git a/1639.cpp b/Problems/1639.cpp diff --git a/README.md b/README.md @@ -443,6 +443,7 @@ for solving problems. | 1438 | Medium | [Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit](Problems/1438.cpp) | | 1443 | Medium | [Minimum Time to Collect All Apples in a Tree](Problems/1443.cpp) | | 1444 | Hard | [Number of Ways of Cutting a Pizza](Problems/1444.cpp) | +| 1456 | Medium | [Maximum Number of Vowels in a Substring of Given Length](Problems/1456.cpp) | | 1462 | Medium | [Course Schedule IV](Problems/1462.cpp) | | 1466 | Medium | [Reorder Routes to Make All Paths Lead to the City Zero](Problems/1466.cpp) | | 1470 | Easy | [Shuffle the Array](Problems/1470.cpp) |