File tree 2 files changed +43
-1
lines changed
2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,894 LeetCode solutions in JavaScript
1
+ # 1,895 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1775
1775
2338|[ Count the Number of Ideal Arrays] ( ./solutions/2338-count-the-number-of-ideal-arrays.js ) |Hard|
1776
1776
2341|[ Maximum Number of Pairs in Array] ( ./solutions/2341-maximum-number-of-pairs-in-array.js ) |Easy|
1777
1777
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|
1778
1779
2349|[ Design a Number Container System] ( ./solutions/2349-design-a-number-container-system.js ) |Medium|
1779
1780
2352|[ Equal Row and Column Pairs] ( ./solutions/2352-equal-row-and-column-pairs.js ) |Medium|
1780
1781
2364|[ Count Number of Bad Pairs] ( ./solutions/2364-count-number-of-bad-pairs.js ) |Medium|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments