-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
def solution(record): | ||
user_name = dict() | ||
chat = [] | ||
chat_uid = [] | ||
for info in record: | ||
_info = info.split(" ") | ||
|
||
if _info[0] in ["Enter", "Leave"]: | ||
chat.append(_info[0]) | ||
chat_uid.append(_info[1]) | ||
# 새로운 user or 새로운 name으로 재 접속 | ||
if _info[0] == "Enter": | ||
user_name[_info[1]] = _info[2] | ||
# change mode | ||
else: | ||
user_name[_info[1]] = _info[2] | ||
|
||
answer = [] | ||
for i in range(len(chat)): | ||
if chat[i] == "Enter": | ||
answer.append(user_name[chat_uid[i]] + "님이 들어왔습니다.") | ||
elif chat[i] == "Leave": | ||
answer.append(user_name[chat_uid[i]] + "님이 나갔습니다.") | ||
|
||
return answer | ||
|
||
|
||
# test | ||
print( | ||
solution( | ||
[ | ||
"Enter uid1234 Muzi", | ||
"Enter uid4567 Prodo", | ||
"Leave uid1234", | ||
"Enter uid1234 Prodo", | ||
"Change uid4567 Ryan", | ||
] | ||
) | ||
) | ||
# result | ||
# ["Prodo님이 들어왔습니다.", "Ryan님이 들어왔습니다.", "Prodo님이 나갔습니다.", "Prodo님이 들어왔습니다."] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
def solution(s): | ||
stack = [] | ||
for c in s: | ||
stack.append(c) | ||
# 짝이 있는 경우 -> stack에서 제거 | ||
if len(stack) >= 2 and stack[-1] == stack[-2]: | ||
stack.pop() | ||
stack.pop() | ||
# stack이 빈 경우 -> 모든 문자들이 제거 됨 | ||
return 1 if not stack else 0 | ||
|
||
|
||
# test | ||
print(solution("baabaa")) | ||
print(solution("cdcd")) |