Skip to content

Commit

Permalink
짝지어 제거하기, 오픈 채팅방 solution 업로드
Browse files Browse the repository at this point in the history
  • Loading branch information
AEJIJEON committed May 12, 2021
1 parent 4ffa020 commit 22e2441
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
41 changes: 41 additions & 0 deletions AejiJeon/programmers/210509sprint/오픈채팅방.py
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님이 들어왔습니다."]
15 changes: 15 additions & 0 deletions AejiJeon/programmers/210509sprint/짝지어제거하기.py
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"))

0 comments on commit 22e2441

Please sign in to comment.