Skip to content

Commit 46bb5c3

Browse files
Merge pull request #1818 from CodingTestStudy2/황은지
[황은지] Day14
2 parents 5b77dcf + af9da84 commit 46bb5c3

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)