We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给定一副牌,每张牌上都写着一个整数。
此时,你需要选定一个数字 X,使我们可以将整副牌按下述规则分成 1 组或更多组:
X
每组都有 X 张牌。 组内所有的牌上都写着相同的整数。 仅当你可选的 X >= 2 时返回 true。
X >= 2
true
Input: deck = [1,2,3,4,4,3,2,1] Output: true Explanation: Possible partition [1,1],[2,2],[3,3],[4,4].
Input: deck = [1,1,1,2,2,2,3,3] Output: false´ Explanation: No possible partition.
Input: deck = [1] Output: false Explanation: No possible partition.
Input: deck = [1,1] Output: true Explanation: Possible partition [1,1].
Input: deck = [1,1,2,2,2,2] Output: true Explanation: Possible partition [1,1],[2,2],[2,2].
1 <= deck.length <= 10^4
0 <= deck[i] < 10^4
The text was updated successfully, but these errors were encountered:
/** * @param {number[]} deck * @return {boolean} */ var hasGroupsSizeX = function(deck) { const counts = new Array(10000).fill(0); for (let i = 0; i < deck.length; i++) { counts[deck[i]] += 1; } let GCD = counts[deck[0]]; for (let i = 0; i < deck.length; i++) { GCD = getGCD(GCD, counts[deck[i]]); if (GCD < 2) { return false; } } return true; function getGCD(a, b) { return a % b === 0 ? b : getGCD(b, a % b); } };
Sorry, something went wrong.
No branches or pull requests
914. X of a Kind in a Deck of Cards
给定一副牌,每张牌上都写着一个整数。
此时,你需要选定一个数字
X
,使我们可以将整副牌按下述规则分成 1 组或更多组:每组都有
X
张牌。组内所有的牌上都写着相同的整数。
仅当你可选的
X >= 2
时返回true
。Example 1
Example 2
Example 3
Example 4
Example 5
Note
1 <= deck.length <= 10^4
0 <= deck[i] < 10^4
The text was updated successfully, but these errors were encountered: