#2347

Best Poker Hand

pupil · 370 · lc easy +23 · verified · 61.6% accepted · 402 likes · top 62%

Description

Five cards are described by an integer array ranks and a character array suits, where the ith card has rank ranks[i] and suit suits[i].

Classify the hand into the best category it qualifies for (listed from strongest to weakest):

- "Flush": all five cards share the same suit.

- "Three of a Kind": at least three cards share the same rank.

- "Pair": at least two cards share the same rank.

- "High Card": none of the above apply.

Return the name of the best hand as a case-sensitive string.

Example 1:

Input: ranks = [13,2,3,1,9], suits = ["a","a","a","a","a"]
Output: "Flush"
Explanation: The hand with all the cards consists of 5 cards with the same suit, so we have a "Flush".

Example 2:

Input: ranks = [4,4,2,4,4], suits = ["d","a","a","b","c"]
Output: "Three of a Kind"
Explanation: The hand with the first, second, and fourth card consists of 3 cards with the same rank, so we have a "Three of a Kind".
Note that we could also make a "Pair" hand but "Three of a Kind" is a better hand.
Also note that other cards could be used to make the "Three of a Kind" hand.

Example 3:

Input: ranks = [10,10,2,12,9], suits = ["a","b","c","a","d"]
Output: "Pair"
Explanation: The hand with the first and second card consists of 2 cards with the same rank, so we have a "Pair".
Note that we cannot make a "Flush" or a "Three of a Kind".

Code

1
2
3