[leetcode, JS] 1684. Count the Number of Consistent Strings

mxxn·2023년 11월 1일
0

leetcode

목록 보기
110/198

문제

문제 링크 : Count the Number of Consistent Strings

풀이

/**
 * @param {string} allowed
 * @param {string[]} words
 * @return {number}
 */
var countConsistentStrings = function(allowed, words) {
    const allowedMap = new Map();
    let result = 0;
    for(let el of allowed) {
      allowedMap.set(el, 1);
    }
    for(let word of words) {
      result++;
      for(let str of word) {
        if(!allowedMap.has(str)) {
          result --;
          break;
        }
      }
    }
    return result;
};
  1. 문자열 allowed에 있는 알파벳으로 Map을 만들고
  2. words 내 문자열들의 알파벳이 allowedMap에 있는지 체크하여 result 계산
  • Runtime 78ms, Memory 51.63MB
profile
내일도 글쓰기

0개의 댓글