Leetcode 950 Solution
This article provides solution to leetcode question 950 (x-of-a-kind-in-a-deck-of-cards)
Access this page by simply typing in "lcs 950" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards
Solution
class Solution:
def hasGroupsSizeX(self, deck: List[int]) -> bool:
if len(deck) == 1:
return False
counters = collections.Counter(deck)
values = list(counters.values())
def gcd(a, b):
if a % b == 0:
return b
return gcd(b, a % b)
ans = values[0]
for i in range(1, len(values)):
ans = gcd(ans, values[i])
if ans == 1:
return False
return True