2 parents 5b77dcf + af9da84 commit 46bb5c3Copy full SHA for 46bb5c3
1 file changed
leetcode3/황은지/914. X of a Kind in a Deck of Cards.js
@@ -0,0 +1,27 @@
1
+/**
2
+ * @param {number[]} deck
3
+ * @return {boolean}
4
+ */
5
+var hasGroupsSizeX = function(deck) {
6
+ if(deck.length===1) return false;
7
+
8
+ const numCount = {};
9
+ for (const num of deck) {
10
+ numCount[num] = (numCount[num] || 0) + 1;
11
+ }
12
13
+ const counts = Object.values(numCount);
14
15
+ let totalGcd=counts[0];
16
17
+ const gcd=(a,b)=>{
18
+ return b===0? a:gcd(b,a%b);
19
20
21
+ for(let i=1;i<counts.length;i++){
22
+ totalGcd=gcd(totalGcd,counts[i]);
23
+ if(totalGcd===1) return false;
24
25
26
+ return totalGcd>=2
27
+};
0 commit comments