niki
BAN USER
Comments (3)
Reputation 35
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
3
of 5 vote
Shuffle the cards in an array[0..51] and then assign each 13 chunks of the randomly shuffled cards to each player
private static int[] shuffleCards(int[] cards){
for(int i=0; i<52; i++){
int rand = new Random().nextInt(52-i)+i;
int temp = cards[i];
cards[i] = cards[rand];
cards[rand] = temp;
}
return cards;
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
This is O(n^2).. the HashMap solution is O(n)
- niki November 15, 2013