Skip to content

Instantly share code, notes, and snippets.

@atul-chaudhary
Created September 10, 2019 02:46
Show Gist options
  • Save atul-chaudhary/072fcc6d7f6478fc0b2a75665587c0aa to your computer and use it in GitHub Desktop.
Save atul-chaudhary/072fcc6d7f6478fc0b2a75665587c0aa to your computer and use it in GitHub Desktop.
leetcode 914: X of a Kind in a Deck of Cards
class Solution:
def hasGroupsSizeX(self, deck) -> bool:
d = {}
for i in range(len(deck)):
if (deck[i] in d):
d[deck[i]] += 1
else:
d[deck[i]] = 1
print(d)
for x in range(2, len(deck) + 1):
if (len(deck) % x == 0):
if all(v%x==0 for v in d.values()):
return True
else:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment