forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_2347.java
35 lines (33 loc) · 1.02 KB
/
_2347.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.fishercoder.solutions;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class _2347 {
public static class Solution1 {
public String bestHand(int[] ranks, char[] suits) {
Set<Character> set = new HashSet<>();
for (char c : suits) {
set.add(c);
}
if (set.size() == 1) {
return "Flush";
}
Map<Integer, Integer> map = new HashMap<>();
for (int i : ranks) {
map.put(i, map.getOrDefault(i, 0) + 1);
}
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
if (entry.getValue() >= 3) {
return "Three of a Kind";
}
}
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
if (entry.getValue() == 2) {
return "Pair";
}
}
return "High Card";
}
}
}