题目
【代码】
执行结果
执行用时:52 ms, 在所有 Python3 提交中击败了89.68% 的用户
内存消耗:18.5 MB, 在所有 Python3 提交中击败了70.87% 的用户
通过测试用例:60 / 60
class Solution:
def lemonadeChange(self, bills: List[int]) -> bool:
ans=True
cnt={5:0,10:0,20:0}
for item in bills:
if item==5:
cnt[item]+=1
elif item==10:
if cnt[5]:
cnt[5]-=1
cnt[10]+=1
else:
return False
else:
if cnt[10] and cnt[5]:
cnt[5]-=1
cnt[10]-=1
cnt[20]+=1
elif cnt[5]>=3:
cnt[5]-=3
else:
return False
return ans
5221



被折叠的 条评论
为什么被折叠?



