[leetcode, JS] 2942. Find Words Containing Character

mxxn·2024년 6월 18일
0

leetcode

목록 보기
185/198

문제

문제 링크 : Find Words Containing Character

풀이

/**
 * @param {string[]} words
 * @param {character} x
 * @return {number[]}
 */
var findWordsContaining = function(words, x) {
    let result = []
    words.forEach( (word, i) => {
        if(word.includes(x)) result.push(i)
    })
    return result
};
  1. 배열 words의 요소들 중 문자 x를 포함하고 있는 것들의 index만 result에 push
  • Runtime 53 ms, Memory 52.86 MB
profile
내일도 글쓰기

0개의 댓글