Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maximum Number of Vowels in a Substring of Given Length #83

Closed
Tracked by #101
fkdl0048 opened this issue Oct 13, 2024 · 0 comments
Closed
Tracked by #101

Maximum Number of Vowels in a Substring of Given Length #83

fkdl0048 opened this issue Oct 13, 2024 · 0 comments
Assignees
Labels
Milestone

Comments

@fkdl0048
Copy link
Owner

fkdl0048 commented Oct 13, 2024

class Solution {
public:
    int maxVowels(string s, int k) {
        unordered_set<char> vowels = {'a', 'e', 'i', 'o', 'u'};
        int n = s.size();
        int current_vowel_count = 0;
        int max_vowel_count = 0;

        for (int i = 0; i < k; i++) {
            if (vowels.count(s[i])) {
                current_vowel_count++;
            }
        }
        max_vowel_count = current_vowel_count;

        for (int i = k; i < n; i++) {

            if (vowels.count(s[i])) {
                current_vowel_count++;
            }

            if (vowels.count(s[i - k])) {
                current_vowel_count--;
            } 

            max_vowel_count = max(current_vowel_count, max_vowel_count);
        }

        return max_vowel_count;
    }
};
  • 슬라이딩 윈도우 기법의 활용 문제
  • 헷갈리던 부분은 숫자가 아닌 배열의 자름을 그냥 Set형태이기 때문에 쉽게 구할 수 있다는 점
@fkdl0048 fkdl0048 mentioned this issue Oct 13, 2024
7 tasks
@fkdl0048 fkdl0048 self-assigned this Oct 13, 2024
@fkdl0048 fkdl0048 added this to Todo Oct 13, 2024
@github-project-automation github-project-automation bot moved this to Todo in Todo Oct 13, 2024
@fkdl0048 fkdl0048 added this to the LeetCode milestone Oct 13, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Todo Oct 14, 2024
@fkdl0048 fkdl0048 mentioned this issue Oct 15, 2024
75 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

1 participant