[LeetCode] 1684. Count the Number of Consistent Strings

Chobby·4일 전
1

LeetCode

목록 보기
578/582

😎풀이

  1. words를 알파벳 단위로 분리
  2. 분리된 words를 순회
    2-1. 현재 단어의 모든 알파벳이 allowed에 포함되었는지 검증
    2-2. 검증되었다면, 1증가
  3. 올바르게 구성된 문자열 수 반환환
function countConsistentStrings(allowed: string, words: string[]): number {
    const wordSplitted = words.map(a => [...a])
    const consisted = wordSplitted.reduce((acc, cur) => {
        const includes = cur.every(a => allowed.includes(a))
        return acc + Number(includes)
    }, 0)
    return consisted
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글