Skip to content

Commit 17e381e

Browse files
committed
Create 914.卡牌分组.js
1 parent 7bad751 commit 17e381e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

914.卡牌分组.js

+27
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+
const map = {};
7+
let max = 0;
8+
for (let i = 0; i < deck.length; i++) {
9+
map[deck[i]] = map[deck[i]] || 0;
10+
map[deck[i]]++;
11+
max = Math.max(max, map[deck[i]]);
12+
}
13+
14+
const countList = Object.values(map);
15+
for (let i = 2; i <= max; i++) {
16+
let j = 0;
17+
for (; j < countList.length; j++) {
18+
if (countList[j] % i !== 0) {
19+
break;
20+
}
21+
}
22+
if (j === countList.length) {
23+
return true;
24+
}
25+
}
26+
return false;
27+
};

0 commit comments

Comments
 (0)