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으로 접근하니까 쉽게 풀렸던 문제
'알고리즘 (with. 백준 문제풀이) > Hash Map & Set' 카테고리의 다른 글
백준 17219번 [비밀번호 찾기] (0) | 2023.09.19 |
---|