[LeetCode] 2062. Count Vowel Substrings of a String

Chobby·6일 전
1

LeetCode

목록 보기
660/710

😎풀이

  1. 모음 정의
  2. word 순회
    2-1. 모음으로 시작되는 지점 정의
    2-2. 한 자씩 늘려가며 모음인 경우만 추가 탐색
    2-3. 모든 모음이 모인 경우 카운트 증가하며 탐색
  3. 카운트 된 횟수 반환
function countVowelSubstrings(word: string): number {
    let count = 0
    const vowels = new Set('aeiou')
    for(let i = 0; i < word.length; i ++) {
        if(!vowels.has(word[i])) continue
        const curStr = new Set(word[i])
        for(let j = i + 1; j < word.length; j++) {
            if(!vowels.has(word[j])) break
            curStr.add(word[j])
            if(curStr.size === vowels.size) count++
        }
    }
    return count
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글