π₯ Algorithm/Programmers
[νλ‘κ·Έλλ¨Έμ€] μ€νμ±ν λ°© (js)
Lennon
2021. 10. 28. 19:31
728x90
λ°μν
https://programmers.co.kr/learn/courses/30/lessons/42888?language=javascript
function solution(record) {
let map = new Map();
let arr = [];
for(let i = 0; i < record.length; i++){
const [state, id, name] = record[i].split(" ");
if(state !== 'Change'){
if(state==='Enter'){
arr.push({id: id, state: "λμ΄ λ€μ΄μμ΅λλ€."});
}
else {
arr.push({id: id, state: "λμ΄ λκ°μ΅λλ€."});
continue;
}
}
map.set(id, name);
}
return arr.map((v) => map.get(v.id)+v.state)
}
ν΄λΉ λ¬Έμ μ idμ nameμ κ²°κ΅ λ§μ§λ§ changeλ enterλ‘ κ²°μ λλ―λ‘
mapμ μ΄μ©ν΄ λ§μ§λ§ κ°μ κ³μ set μμΌ°λ€.
κ·Έ ν λ€μ΄μμ΅λλ€, λκ°μ΅λλ€ κ°μ²΄ idλ₯Ό mapμμ κ°μ Έμ 리ν΄ν΄μ£Όλ©΄ λ~~
μ΄λ° λμ λͺ¨λ κ±Έ κ²°μ νλ λ¬Έμ λ setμ΄λ mapμ μ΄μ©νλ©΄ ν¨μ¨μ μ΄κ² ν μ μλ€λ κ±Έ κΉ¨λ¬μλ€.
728x90
λ°μν