회고
[개발일지] - 157(연차)
Happy Programmer
2023. 12. 4. 23:10
(1).백준 25801번 Odd/Even Strings는 사용된 각 철자의 개수가 모두 홀수인 경우 1를 출력하고
모두 짝수인 경우 0을 출력하고 둘 모두 섞인 경우 0/1을 출력해야 하는 문제였다.
각 철자별로 map에 담아 각 철자의 개수를 확인하고
odd와 even의 개수를 다시 odd와 even에 담은 다음
둘 모두 1보다 클 경우 혼합이니 0/1을 출력했고
둘 중 하나만 있는 경우 0 또는 1을 출력했다.
const input = `funnyn`
const spellCheck = {}
let odd = 0
let even = 0
for(let i = 0 ; i < input.length ; i++){
if(spellCheck[input[i]]){
spellCheck[input[i]]++
}
else{
spellCheck[input[i]] = 1
}
}
for(key in spellCheck){
if(spellCheck[key] % 2){
odd++
}
else{
even++
}
}
if(odd > 0 && even > 0){
console.log('0/1')
}
else if(odd > 0){
console.log(1)
}
else{
console.log(0)
}