File tree 2 files changed +25
-0
lines changed
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 238
238
884|[ Uncommon Words from Two Sentences] ( ./0884-uncommon-words-from-two-sentences.js ) |Easy|
239
239
890|[ Find and Replace Pattern] ( ./0890-find-and-replace-pattern.js ) |Medium|
240
240
905|[ Sort Array By Parity] ( ./0905-sort-array-by-parity.js ) |Easy|
241
+ 914|[ X of a Kind in a Deck of Cards] ( ./0914-x-of-a-kind-in-a-deck-of-cards.js ) |Medium|
241
242
916|[ Word Subsets] ( ./0916-word-subsets.js ) |Medium|
242
243
922|[ Sort Array By Parity II] ( ./0922-sort-array-by-parity-ii.js ) |Easy|
243
244
925|[ Long Pressed Name] ( ./0925-long-pressed-name.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 914. X of a Kind in a Deck of Cards
3
+ * https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given an integer array deck where deck[i] represents the number written on the ith card.
7
+ *
8
+ * Partition the cards into one or more groups such that:
9
+ * - Each group has exactly x cards where x > 1, and
10
+ * - All the cards in one group have the same integer written on them.
11
+ *
12
+ * Return true if such partition is possible, or false otherwise.
13
+ */
14
+
15
+ /**
16
+ * @param {number[] } deck
17
+ * @return {boolean }
18
+ */
19
+ var hasGroupsSizeX = function ( deck ) {
20
+ const gcd = ( a , b ) => ! b ? a : gcd ( b , a % b ) ;
21
+ const map = new Map ( ) ;
22
+ deck . forEach ( n => map . set ( n , ( map . get ( n ) || 0 ) + 1 ) ) ;
23
+ return [ ...map . values ( ) ] . reduce ( gcd ) > 1 ;
24
+ } ;
You can’t perform that action at this time.
0 commit comments