2019 KAKAO BLIND RECRUITMENT - 오픈채팅방 (Level 2)

 

https://programmers.co.kr/learn/courses/30/lessons/42888


Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def solution(record):
    records    = record
    name_table = {}

    msgs_info = []
    for record in records:
        infos = record.split()
        if infos[0] == 'Enter':
            _, uid, name = infos
            name_table[uid] = name
            msgs_info.append((uid, '님이 들어왔습니다.'))
        elif infos[0] == 'Leave':
            _, uid = infos
            msgs_info.append((uid, "님이 나갔습니다."))
        elif infos[0] == 'Change':
            _, uid, name = infos
            name_table[uid] = name
    return [f"{name_table[uid]}{stat}" for uid, stat in msgs_info]

Complexity

$O(n)$

  • $n: \text{record} $