[LeetCode] 2255. Count Prefixes of a Given String

Chobby·2일 전
1

LeetCode

목록 보기
698/710

😎풀이

  1. words 순회
    1-1. s의 접두사인 경우 탐색
    1-2. s의 접두사라면, 카운트
  2. 카운트 반환
function countPrefixes(words: string[], s: string): number {
    let count = 0
    for(const word of words) {
        if(s.startsWith(word)) count++
    }
    return count
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글