1 Star 3 Fork 5

刘炜/python LeetCode

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0914卡牌分组.py 1009 Bytes
一键复制 编辑 原始数据 按行查看 历史
刘炜 提交于 2020-03-27 12:58 +08:00 . 素数筛 + 暴力枚举
class Solution:
def hasGroupsSizeX(self, deck: List[int]) -> bool:
numdic = {}
for num in deck:
if num in numdic.keys():
numdic[num] += 1
else:
numdic[num] = 1
minlen = -1
for l in numdic.values():
if minlen == -1 or l < minlen:
minlen = l
if minlen < 2:
return False
def simple(x):#求[2,x]之间的素数
simlist = [0] * (x+1)
rlt = []
for i in range(2,x+1,1):
if simlist[i] == 1:
continue
rlt.append(i)
for j in range(i+i,x+1,i):
simlist[i] = 1
return rlt
for num in simple(minlen):
isnum = True
for val in numdic.values():
if val % num != 0:
isnum = False
if isnum:
return True
return False
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/new_way/python-LeetCode.git
git@gitee.com:new_way/python-LeetCode.git
new_way
python-LeetCode
python LeetCode
master

搜索帮助