BootCamp 40day

GyeongNamΒ·2024λ…„ 1μ›” 11일
0

BootCamp

λͺ©λ‘ 보기
34/49
post-thumbnail

πŸ“… 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()))];
profile
503 Service Unavailable Error

0개의 λŒ“κΈ€