[Algorithm] 17 week(5.02 ~ 5.08) 1/3

Dev_min·2022년 5월 2일
0

algorithm

목록 보기
53/157

2085. Count Common Words With One Occurrence

var countWords = function(words1, words2) {
    const keyValue = {};
    let result = 0;
    
    for(let i = 0; i < words1.length; i++){
        for(let j = 0; j < words2.length; j++){      
            if(words1[i] === words2[j]){
                if(!keyValue[words1[i]]){
                    keyValue[words1[i]] = 1;
                }else {
                    keyValue[words1[i]] += 1;
                }
            }
        }
    }

    Object.values(keyValue).forEach((value) => {
        if(value === 1){
            result += 1;
        }
    })
    
    return result;
};
profile
TIL record

0개의 댓글