본문 바로가기
알고리즘 (with. 백준 문제풀이)/Hash Map & Set

백준 25192번 [인사성 밝은 곰곰이]

by 천릉객 2023. 9. 21.
const input = require('fs')
    .readFileSync('/dev/stdin')
    .toString()
    .trim()
    .split('\n')
const [n, ...test] = input
const hashSet = new Set();

let answer = 0;

test.map((str) => {
    if(str == "ENTER"){
        answer += hashSet.size
        hashSet.clear()
    }
    else{
        hashSet.add(str);
    }
})
answer += hashSet.size

console.log(answer)

문자열과 나온 횟수를 map으로 풀려고 시도하다가 set으로 접근하니까 쉽게 풀렸던 문제