Skip to content

Commit e13fb6a

Browse files
committed
Add solution #2347
1 parent 1fdb40c commit e13fb6a

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,894 LeetCode solutions in JavaScript
1+
# 1,895 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1775,6 +1775,7 @@
17751775
2338|[Count the Number of Ideal Arrays](./solutions/2338-count-the-number-of-ideal-arrays.js)|Hard|
17761776
2341|[Maximum Number of Pairs in Array](./solutions/2341-maximum-number-of-pairs-in-array.js)|Easy|
17771777
2342|[Max Sum of a Pair With Equal Sum of Digits](./solutions/2342-max-sum-of-a-pair-with-equal-sum-of-digits.js)|Medium|
1778+
2347|[Best Poker Hand](./solutions/2347-best-poker-hand.js)|Easy|
17781779
2349|[Design a Number Container System](./solutions/2349-design-a-number-container-system.js)|Medium|
17791780
2352|[Equal Row and Column Pairs](./solutions/2352-equal-row-and-column-pairs.js)|Medium|
17801781
2364|[Count Number of Bad Pairs](./solutions/2364-count-number-of-bad-pairs.js)|Medium|

solutions/2347-best-poker-hand.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* 2347. Best Poker Hand
3+
* https://leetcode.com/problems/best-poker-hand/
4+
* Difficulty: Easy
5+
*
6+
* You are given an integer array ranks and a character array suits. You have 5 cards where the
7+
* ith card has a rank of ranks[i] and a suit of suits[i].
8+
*
9+
* The following are the types of poker hands you can make from best to worst:
10+
* 1. "Flush": Five cards of the same suit.
11+
* 2. "Three of a Kind": Three cards of the same rank.
12+
* 3. "Pair": Two cards of the same rank.
13+
* 4. "High Card": Any single card.
14+
*
15+
* Return a string representing the best type of poker hand you can make with the given cards.
16+
*
17+
* Note that the return values are case-sensitive.
18+
*/
19+
20+
/**
21+
* @param {number[]} ranks
22+
* @param {character[]} suits
23+
* @return {string}
24+
*/
25+
var bestHand = function(ranks, suits) {
26+
const suitCount = new Map();
27+
const rankCount = new Map();
28+
29+
for (let i = 0; i < 5; i++) {
30+
suitCount.set(suits[i], (suitCount.get(suits[i]) || 0) + 1);
31+
rankCount.set(ranks[i], (rankCount.get(ranks[i]) || 0) + 1);
32+
}
33+
34+
if (suitCount.size === 1) return 'Flush';
35+
36+
const maxRankCount = Math.max(...rankCount.values());
37+
if (maxRankCount >= 3) return 'Three of a Kind';
38+
if (maxRankCount === 2) return 'Pair';
39+
40+
return 'High Card';
41+
};

0 commit comments

Comments
 (0)