-
Notifications
You must be signed in to change notification settings - Fork 1
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
재귀로도 풀이하신 게 인상 깊네요 ㅎㅎ 근데 시간이 2배 이상 걸린다니.. 저도 이유가 궁금하네요!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
큐에 대한 이해를 완벽하게 잘 하신 것 같고, 재귀에 대해서도 이제 이해를 하시게 된 것 같아서 제가 다 뿌듯하네요!
queue = deque([i for i in range(1, N+1)]) # 카드 덱 구성 | ||
|
||
while True: | ||
if len(queue)==1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요렇게 쓰는 것 보다는
while len(queue)!=1:
...
print(queue[0])
이렇게 쓰는 편이 더 깔끔할 것 같습니다!
break | ||
queue.popleft() # 맨 위에 있는 카드 버림 | ||
out = queue.popleft() # 그 다음 위에 있는 카드를 선택 | ||
queue.append(out) # 해당 카드를 맨 밑으로 옮김 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요것도
queue.append(queue.popleft())
요렇게 자주 씁니다! popleft & pop은 원소를 제거함과 동시에 그 원소를 반환해주니까요!
N = int(input()) | ||
queue = deque([i for i in range(1, N+1)]) | ||
|
||
def run(cards): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
재귀로 풀어볼 생각은 1도 못했는데 재밌네요!!
재귀를 활용하게 되면 재귀가 거듭되면서 수행한 작업들을 메모리 영역에 모두 들고 있어야 해서 오버헤드가 더 심해집니다! 그래서 시간이나 메모리가 더 소요되는 것 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
전체적인 풀이가 비슷하네요 이번에 재귀로 접근하시는 걸 보고 재귀 복습을 확실히 하신 것 같아 감탄이 나옵니다!! 고생하셨어요!
PR Summary
풀이시간
접근법
회고
ISSUE NUMBER