[leetcode]914. X of a Kind in a Deck of Cards (easy)
题目原意可转换为
两组有大于等于2的公因数
/**
* @param {number[]} deck
* @return {boolean}
*/
var hasGroupsSizeX = function(deck) {
var map = {};
for (let i = 0; i < deck.length; i++) {
if (map[deck[i]])
map[deck[i]] += 1;
else
map[deck[i]] = 1;
}
var min = map[deck[0]];
for (var i in map) {
if (map[i] <= min) {
min = map[i];
}
}
if (min < 2) {
return false;
}
var flag;
for (var i = 2; i <= min; i++) {
flag = true;
for (var k in map) {
if (map[k] % i != 0) {
flag = false;
break;
}
}
if (flag) {
return true;
}
}
return false;
};