Ai
1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
hand-of-straights.py 745 Bytes
一键复制 编辑 原始数据 按行查看 历史
Sanghee Kim 提交于 2019-01-30 03:41 +08:00 . update hand-of-straights.py
# Time: O(nlogn)
# Space: O(n)
from collections import Counter
from heapq import heapify, heappop
class Solution(object):
def isNStraightHand(self, hand, W):
"""
:type hand: List[int]
:type W: int
:rtype: bool
"""
if len(hand) % W:
return False
counts = Counter(hand)
min_heap = list(hand)
heapify(min_heap)
for _ in xrange(len(min_heap)//W):
while counts[min_heap[0]] == 0:
heappop(min_heap)
start = heappop(min_heap)
for _ in xrange(W):
counts[start] -= 1
if counts[start] < 0:
return False
start += 1
return True
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

搜索帮助