Skip to content

Instantly share code, notes, and snippets.

@perilstar
Created January 24, 2017 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perilstar/0c1992a832d8c90ee97d58a5a512aa5d to your computer and use it in GitHub Desktop.
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
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