[leetcode, JS] 2586. Count the Number of Vowel Strings in Range

mxxn·2024년 6월 3일
0

leetcode

목록 보기
170/198

문제

문제 링크 : Count the Number of Vowel Strings in Range

풀이

/**
 * @param {string[]} words
 * @param {number} left
 * @param {number} right
 * @return {number}
 */
var vowelStrings = function(words, left, right) {
    const vowel = 'aeiou'
    let count = 0
    for(let i=left; i<=right; i++) {
        const word = words[i]
        if(vowel.includes(word[0]) && vowel.includes(word[word.length-1])) count++
    }

    return count
};
  1. words의 left index부터 right index까지만 for문을 돌리고
  2. 해당 word의 앞자리, 끝자리가 vowel인지 확인하여 카운팅
  • Runtime 74 ms, Memory 53.26 MB
profile
내일도 글쓰기

0개의 댓글