Open
Conversation
deok-beom
reviewed
Nov 24, 2023
| import java.util.*; | ||
|
|
||
| public class Deck { | ||
| private static final Deque<Card> cards = new ArrayDeque<>(); |
There was a problem hiding this comment.
과연 LinkedList보다 ArrayDeque가 더 효율적이겠네요 🤔
Comment on lines
+13
to
+18
| public void shuffle() { | ||
| List<Card> cardList = new ArrayList<>(cards); | ||
| Collections.shuffle(cardList); | ||
| cards.clear(); | ||
| cards.addAll(cardList); | ||
| } |
There was a problem hiding this comment.
이 로직을 보고 처음에 만들어지는 정렬된 카드 배열을 캐싱하면 어떨까 생각해보았습니다.
최초 초기화 블록에서 생성한 카드 뭉치를 별도로 저장해놓고 섞인 새로운 카드 뭉치가 필요할 때 복사해서 셔플만 하면 카드 뭉치를 다시 생성하는 시간을 아낄 수 있겠네요.
문제에서는 게임을 단 한 번밖에 진행하고 있어서 이러한 로직은 필요 없지만... 추후에 게임을 여러번 반복해서 진행하도록 패치한다면 실행 시간을 줄이는데 큰 도움이 될 것 같습니다. 👍
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.
No description provided.