Skip to content
LC-2347 Easy LeetCode

2347. Best Poker Hand

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 61% Topics: Array, Hash Table, Counting
View full problem on LeetCode

Reading material

Reference solution (spoiler · python)
# Time:  O(1)
# Space: O(1)

# freq table
class Solution(object):
    def bestHand(self, ranks, suits):
        """
        :type ranks: List[int]
        :type suits: List[str]
        :rtype: str
        """
        LOOKUP = ["", "High Card", "Pair", "Three of a Kind", "Three of a Kind", "Three of a Kind"]
        if all(suits[i] == suits[0] for i in xrange(1, len(suits))):
            return "Flush"
        cnt = [0]*13
        for x in ranks:
            cnt[x-1] += 1
        return LOOKUP[max(cnt)]

Solution from kamyu104/LeetCode-Solutions · MIT