Open
Conversation
Owner
|
deque의 popleft 와 list 의 pop(0) 은 하는 역활은같지만 popleft 가 pop(0) 보다 훨신 빠릅니다 그렇기 때문에 이전에 리스트로 트라이 했을때 시간초과가 난거 같습니다. 조금더 자세히 설명 드리자면 list 의 pop(0) 은 리스트가 가지고 있는 모든 데이터를 순회하고 제거하기 때문에 자료 갯수가 n 개라면 O(n) 즉 자료 갯수만큼 시간이 듭니다 그러면 자료가 많아질수로 시간이 더 오래 걸리겠죠 하지만 deque는 양방향 큐이기 때문에 왼쪽에서 popleft() 을 해도 데이터를 순회 하지 않고 stack 처럼 바로 뽑기 때문에 O(1) 즉 항상 1초 (상수 시간복잡도라고도 합니다.)가 걸리기때문에 훨신빠름니다! |
Collaborator
Author
|
와... 정말 자세한 설명 감사드려요!!! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Queue를 사용하여 풀었습니다.
신기한 점은
동일한 알고리즘을 list 로 풀었을때는 시간초과가 되었습니다.
하지만, from collections import deque 하여
list를 deque로 변형만 해줘도 시간초과가 발생하지 않았습니다.