Skip to content

Commit c525860

Browse files
authored
Create best-poker-hand.py
1 parent 5a11d2a commit c525860

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Python/best-poker-hand.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(1)
2+
# Space: O(1)
3+
4+
# freq table
5+
class Solution(object):
6+
def bestHand(self, ranks, suits):
7+
"""
8+
:type ranks: List[int]
9+
:type suits: List[str]
10+
:rtype: str
11+
"""
12+
LOOKUP = ["", "High Card", "Pair", "Three of a Kind", "Three of a Kind", "Three of a Kind"]
13+
if all(suits[i] == suits[0] for i in xrange(1, len(suits))):
14+
return "Flush"
15+
cnt = [0]*13
16+
for x in ranks:
17+
cnt[x-1] += 1
18+
return LOOKUP[max(cnt)]

0 commit comments

Comments
 (0)