내가 푼 코드
function solution(record) { let answer = []; let userData = {}; let chatLog = []; for (const data of record) { const enter = data.split(" ")[0] const userId = data.split(" ")[1] const userName = data.split(" ")[2] if (enter === "Leave") { chatLog.push([userId, "님이 나갔습니다."]) } else if (enter === "Enter") { userData = { ...userData, [userId]: userName }; chatLog.push([userId, "님이 들어왔습니다."]) } else if (enter === "Change") { userData = { ...userData, [userId]: userName }; } } for (const log of chatLog) { answer.push(userData[log[0]] + log[1]) } return answer; } console.log(solution(["Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234","Enter uid1234 Prodo","Change uid4567 Ryan"]))

시간초과로 인해 테스트케이스를 통과하지 못하는데, 시간복잡도에 대한 개념이 부족해서 해결하지 못했다.
일단 기록해두고 나중에 다시 와서 풀자.
'프로그래밍 > 알고리즘' 카테고리의 다른 글
프로그래머스 - 프린터 (0) | 2021.04.08 |
---|---|
프로그래머스 124 나라의 숫자 (0) | 2021.04.08 |
Github Action사용법 + Push하면 바로 deploy 되게 하기 (0) | 2021.04.06 |
프로그래머스 KAKAO 2021 문제 - 신규 아이디 추천 (0) | 2021.04.03 |
프로그래머스 KAKAO 2019 문제 - 크레인 인형 뽑기 (0) | 2021.04.02 |