Skip to content

Conversation

@ca1af
Copy link
Collaborator

@ca1af ca1af commented Nov 23, 2023

No description provided.

import java.util.*;

public class Deck {
private static final Deque<Card> cards = new ArrayDeque<>();

Choose a reason for hiding this comment

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

과연 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);
}
Copy link

@deok-beom deok-beom Nov 24, 2023

Choose a reason for hiding this comment

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

이 로직을 보고 처음에 만들어지는 정렬된 카드 배열을 캐싱하면 어떨까 생각해보았습니다.
최초 초기화 블록에서 생성한 카드 뭉치를 별도로 저장해놓고 섞인 새로운 카드 뭉치가 필요할 때 복사해서 셔플만 하면 카드 뭉치를 다시 생성하는 시간을 아낄 수 있겠네요.
문제에서는 게임을 단 한 번밖에 진행하고 있어서 이러한 로직은 필요 없지만... 추후에 게임을 여러번 반복해서 진행하도록 패치한다면 실행 시간을 줄이는데 큰 도움이 될 것 같습니다. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants