[LeetCode] 2185. Counting Words With a Given Prefix

Chobby·4일 전
1

LeetCode

목록 보기
683/710

😎풀이

  1. words 순회
    1-1. 각 문자가 pref로 시작하는지 검사
    1-2. 조건을 만족하는 경우 카운트
  2. 카운트 반환
function prefixCount(words: string[], pref: string): number {
    let count = 0
    for(const word of words) {
        if(word.startsWith(pref)) count++
    }
    return count
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글