Leetcode 914. X of a Kind in a Deck of Cards
Posted SnailTyan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode 914. X of a Kind in a Deck of Cards相关的知识,希望对你有一定的参考价值。
文章作者: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
以上是关于Leetcode 914. X of a Kind in a Deck of Cards的主要内容,如果未能解决你的问题,请参考以下文章
914. X of a Kind in a Deck of Cards
hdu3306:Another kind of Fibonacci