π
2024λ
01μ 10μΌ
40μΌμ°¨ : javaScript λ¬Έμ νμ΄
function solution(record: string[]): string[] {
const map: Map<string, string> = new Map();
let changeCount: number = 0;
for (let i = 0; i < record.length; i++) {
const strArr: string[] = record[i].split(" ");
if (strArr[0] === "Leave") {
continue;
} else if (strArr[0] === "Change") {
changeCount++;
}
map.set(strArr[1], strArr[2]);
}
const answer: string[] = new Array(record.length - changeCount);
let index: number = 0;
for (let i = 0; i < record.length; i++) {
const strArr: string[] = record[i].split(" ");
if (strArr[0] === "Enter") {
answer[index] = `${map.get(strArr[1])}λμ΄ λ€μ΄μμ΅λλ€.`;
index++;
} else if (strArr[0] === "Leave") {
answer[index] = `${map.get(strArr[1])}λμ΄ λκ°μ΅λλ€.`;
index++;
}
}
return answer;
}
const ts = new Set();
for (const opStr of operations) {
const st = opStr.split(" ");
if (st[0] === "I") {
const value = parseInt(st[1]);
ts.add(value);
} else if (ts.size > 0 && opStr === "D 1") {
ts.delete(Math.max(...Array.from(ts.values())));
} else if (ts.size > 0 && opStr === "D -1") { ts.delete(Math.min(...Array.from(ts.values()))); }
}
return ts.size === 0 ? [0, 0] : [Math.max(...Array.from(ts.values())), Math.min(...Array.from(ts.values()))];