Skip to content

Latest commit

 

History

History
39 lines (33 loc) · 1.02 KB

2347.最好的扑克手牌.md

File metadata and controls

39 lines (33 loc) · 1.02 KB

2347.最好的扑克手牌

/*
 * @lc app=leetcode.cn id=2347 lang=typescript
 *
 * [2347] 最好的扑克手牌
 */

// @lc code=start
function bestHand(ranks: number[], suits: string[]): string {}
// @lc code=end

解法 1: 模拟

function bestHand(ranks: number[], suits: string[]): string {
  if (suits.every(a => a === suits[0])) return 'Flush'
  const set = new Set(ranks)
  for (const num of set) {
    if (ranks.filter(a => a === num).length >= 3) return 'Three of a Kind'
  }
  if (set.size < 5) return 'Pair'
  return 'High Card'
}

Case

test.each([
  { input: { ranks: [13, 2, 3, 1, 9], suits: ['a', 'a', 'a', 'a', 'a'] }, output: 'Flush' },
  { input: { ranks: [4, 4, 2, 4, 4], suits: ['d', 'a', 'a', 'b', 'c'] }, output: 'Three of a Kind' },
  { input: { ranks: [10, 10, 2, 12, 9], suits: ['a', 'b', 'c', 'a', 'd'] }, output: 'Pair' },
])('input: ranks = $input.ranks, suits = $input.suits', ({ input: { ranks, suits }, output }) => {
  expect(bestHand(ranks, suits)).toEqual(output)
})