Skip to content
This repository was archived by the owner on Mar 18, 2024. It is now read-only.

[2023-09-20] dohyun #239 #257

Merged
merged 1 commit into from
Sep 21, 2023
Merged

[2023-09-20] dohyun #239 #257

merged 1 commit into from
Sep 21, 2023

Conversation

limstonestone
Copy link
Contributor

PR Summary

풀이시간

  • 약 15분

접근법

  • N이 1만 -> O(N^2) ~ O(NlogN)
  • 유저가 나중에 닉변하는 경우를 생각해서 결과를 순회할 때 배열에 저장하는 행위를 한번 해야함
  • 고유 아이디는 그대로 -> 이거를 딕셔너리로 활용하자

회고

  • 시간복잡도나 코드를 조금 더 간결하게 할 수 있을 것 같다는 생각
    • 여러분들의 코드를 잘 공부해보겠습니다!!

ISSUE NUMBER

@limstonestone limstonestone self-assigned this Sep 20, 2023
@limstonestone limstonestone linked an issue Sep 20, 2023 that may be closed by this pull request
Copy link
Member

@Woo-Yeol Woo-Yeol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전체적으로 깔끔한 코드로 작성된 것 같아서 보기 편했습니다 고생하셨어요 도현님!

answer = []

for record in records:
behavior, code, *user = record.split()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 이렇게 빈 리스트도 받을 수 있군요 좋은 방식 감사합니다 도현님!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 저도 몰랐던 내용이네요! 하지만 협업할 때 이렇게 사용하기 위해서는 따로 명시를 해줘야 할 것 같아요 ㅎㅎ;;

from collections import defaultdict

def solution(records):
users = defaultdict()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굳이 defaultdict가 아니라 그냥 dict로 써줘도 될 것 같아요!

elif behavior == "Leave":
answer.append([code, "님이 나갔습니다."])

for i in range(len(answer)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서는 문제가 안되지만 원래 리스트를 순회하면서 리스트의 원소를 변경하는게 안전한 방법은 아니라 별도의 리스트를 사용하는 방법도 좋을 것 같아요! 고생하셨습니다 도현님~~!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 순회중인 인덱스 이전의 원소만 업데이트 하는 건 크게 문제가 안될 것 같지만(dp문제에서 그러듯이), 만약 다시 현재 인덱스를 방문해야 하거나, 리스트 원소의 개수가 바뀌어 버리는 경우 안전하지 않은 게 맞습니다! 실제로 순회 중에 리스트 원소 개수가 바뀌면 에러납니다! 참고하시면 좋을 것 같아요.

answer = []

for record in records:
behavior, code, *user = record.split()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 저도 몰랐던 내용이네요! 하지만 협업할 때 이렇게 사용하기 위해서는 따로 명시를 해줘야 할 것 같아요 ㅎㅎ;;

elif behavior == "Leave":
answer.append([code, "님이 나갔습니다."])

for i in range(len(answer)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 순회중인 인덱스 이전의 원소만 업데이트 하는 건 크게 문제가 안될 것 같지만(dp문제에서 그러듯이), 만약 다시 현재 인덱스를 방문해야 하거나, 리스트 원소의 개수가 바뀌어 버리는 경우 안전하지 않은 게 맞습니다! 실제로 순회 중에 리스트 원소 개수가 바뀌면 에러납니다! 참고하시면 좋을 것 같아요.

@limstonestone limstonestone merged commit 09b697c into main Sep 21, 2023
@limstonestone limstonestone deleted the dohyun-#239 branch September 21, 2023 15:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Programmers] 오픈채팅방
4 participants