LeetCode - 2085. Count Common Words With One Occurrence

henu·2024년 1월 18일
0

LeetCode

목록 보기
162/186

Solution

var countWords = function(words1, words2) {
    const filtered1 = words1.filter(e => words1.indexOf(e) === words1.lastIndexOf(e))
    const filtered2 = words2.filter(e => words2.indexOf(e) === words2.lastIndexOf(e))

    let count = 0

    for(word of filtered1) {
        if(filtered2.includes(word)) count++
    }

    return count
};

Explanation

0개의 댓글