알고리즘 스터디 2021.07~
[프로그래머스] 2019 카카오 오픈채팅방
cme10575
2021. 7. 8. 20:43
https://programmers.co.kr/learn/courses/30/lessons/42888
코딩테스트 연습 - 오픈채팅방
오픈채팅방 카카오톡 오픈채팅방에서는 친구가 아닌 사람들과 대화를 할 수 있는데, 본래 닉네임이 아닌 가상의 닉네임을 사용하여 채팅방에 들어갈 수 있다. 신입사원인 김크루는 카카오톡 오
programmers.co.kr
풀이
딕셔너리에 id별로 닉네임 저장 ex) {id1: 'prodo', id2: 'ryan' ... }
swich case 문으로 'enter' 'leave' 'change' 처리
마지막에 value값으로 매핑해서 반환
def solution(record):
idDic = {}
answer = []
for r in record:
words = r.split()
if words[0] != 'Leave':
idDic[words[1]] = words[2]
for r in record:
words = r.split()
if words[0] == 'Enter':
answer.append(idDic[words[1]] + "님이 들어왔습니다.")
elif words[0] == 'Leave':
answer.append(idDic[words[1]] + "님이 나갔습니다.")
return answer
O(n)시간복잡도를 가진다.
쉬웠다,.. 이게 어떻게 레벨 2지..!?