文章作者:Tyan 博客:noahsnail.com | CSDN | 简书
1. Description
2. Solution
**解析:**Version 1,统计元素个数,遍历所有可能的分割数量,下限为2
,上限为最少的元素个数,如果满足条件,返回True
。
- Version 1
class Solution:
def hasGroupsSizeX(self, deck: List[int]) -> bool:
stat = collections.Counter(deck)
for j in range(2, min(stat.values()) 1):
flag = True
for val in stat.values():
if val % j != 0:
flag = False
break
if flag:
return True
return False
Reference
- https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards/