Best Poker Hand LeetCode solution in Java

1
class Solution {
2
public String bestHand(int[] ranks, char[] suits) {
3
int max = 0;
4
int card = 0;
5
char ch = suits[0];
6
int[] arr = new int[14];
7
for (int i = 0; i < 5; i++) {
8
arr[ranks[i]]++;
9
max = Math.max(max, arr[ranks[i]]);
10
if (suits[i] == ch) card++;
11
}
12
if (card == 5) return "Flush";
13
return max >= 3 ? "Three of a Kind" : (max == 2 ? "Pair" : "High Card");
14
}
15
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0