Class Solution

java.lang.Object
g2301_2400.s2347_best_poker_hand.Solution

public class Solution extends Object
2347 - Best Poker Hand.<p>Easy</p> <p>You are given an integer array <code>ranks</code> and a character array <code>suits</code>. You have <code>5</code> cards where the <code>i<sup>th</sup></code> card has a rank of <code>ranks[i]</code> and a suit of <code>suits[i]</code>.</p> <p>The following are the types of <strong>poker hands</strong> you can make from best to worst:</p> <ol> <li><code>&quot;Flush&quot;</code>: Five cards of the same suit.</li> <li><code>&quot;Three of a Kind&quot;</code>: Three cards of the same rank.</li> <li><code>&quot;Pair&quot;</code>: Two cards of the same rank.</li> <li><code>&quot;High Card&quot;</code>: Any single card.</li> </ol> <p>Return <em>a string representing the <strong>best</strong> type of <strong>poker hand</strong> you can make with the given cards.</em></p> <p><strong>Note</strong> that the return values are <strong>case-sensitive</strong>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> ranks = [13,2,3,1,9], suits = [&ldquo;a&rdquo;,&ldquo;a&rdquo;,&ldquo;a&rdquo;,&ldquo;a&rdquo;,&ldquo;a&rdquo;]</p> <p><strong>Output:</strong> &ldquo;Flush&rdquo;</p> <p><strong>Explanation:</strong> The hand with all the cards consists of 5 cards with the same suit, so we have a &ldquo;Flush&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> ranks = [4,4,2,4,4], suits = [&ldquo;d&rdquo;,&ldquo;a&rdquo;,&ldquo;a&rdquo;,&ldquo;b&rdquo;,&ldquo;c&rdquo;]</p> <p><strong>Output:</strong> &ldquo;Three of a Kind&rdquo;</p> <p><strong>Explanation:</strong> The hand with the first, second, and fourth card consists of 3 cards with the same rank, so we have a &ldquo;Three of a Kind&rdquo;.</p> <p>Note that we could also make a &ldquo;Pair&rdquo; hand but &ldquo;Three of a Kind&rdquo; is a better hand.</p> <p>Also note that other cards could be used to make the &ldquo;Three of a Kind&rdquo; hand.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> ranks = [10,10,2,12,9], suits = [&ldquo;a&rdquo;,&ldquo;b&rdquo;,&ldquo;c&rdquo;,&ldquo;a&rdquo;,&ldquo;d&rdquo;]</p> <p><strong>Output:</strong> &ldquo;Pair&rdquo;</p> <p><strong>Explanation:</strong> The hand with the first and second card consists of 2 cards with the same rank, so we have a &ldquo;Pair&rdquo;.</p> <p>Note that we cannot make a &ldquo;Flush&rdquo; or a &ldquo;Three of a Kind&rdquo;.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>ranks.length == suits.length == 5</code></li> <li><code>1 <= ranks[i] <= 13</code></li> <li><code>'a' <= suits[i] <= 'd'</code></li> <li>No two cards have the same rank and suit.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • bestHand

      public String bestHand(int[] ranks, char[] suits)