Created
January 24, 2017 20:46
-
-
Save perilstar/0c1992a832d8c90ee97d58a5a512aa5d to your computer and use it in GitHub Desktop.
Determine if a set of cards (represented by int values) has a full house in linear time
This file contains 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
public static boolean hasFullHouse(int[] arrIn) { | |
int[] count = new int[13]; | |
int two = 0, | |
threeOrGreater = 0; | |
for (int i = 0; i < arrIn.length; i++) { | |
count[arrIn[i] - 1]++; | |
} | |
for (int i = 0; i < 13; i++) { | |
if (count[i] == 2) { | |
two++; | |
} else if (count[i] >= 3) { | |
threeOrGreater++; | |
} | |
} | |
return threeOrGreater >= 2 || (two >= 1 && threeOrGreater >= 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment