914. X of a Kind in a Deck of Cards
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 30% Topics: Array, Hash Table, Math, Counting, Number Theory
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n * (logn)^2)
# Space: O(n)
import collections
class Solution(object):
def hasGroupsSizeX(self, deck):
"""
:type deck: List[int]
:rtype: bool
"""
def gcd(a, b): # Time: O((logn)^2)
while b:
a, b = b, a % b
return a
vals = collections.Counter(deck).values()
return reduce(gcd, vals) >= 2
Solution from kamyu104/LeetCode-Solutions · MIT