Re: [闲聊] 每日leetcode

楼主: DJYOMIYAHINA (通通打死)   2024-12-06 23:13:35
怪怪的题目
感觉有一些更聪明的解法==
应该至少可以binary search吧
不过有点懒得改了
def maxCount(self, banned: List[int], n: int, maxSum: int) -> int:
banned = set(banned)
cur_sum, cur_cnt = 0, 0
for i in range(1,n+1):
if i in banned:
continue
cur_sum += i
if cur_sum>maxSum:
return cur_cnt
cur_cnt += 1
return cur_cnt
作者: sustainer123 (caster)   2024-12-06 23:30:00
我写得差不多

Links booklink

Contact Us: admin [ a t ] ucptt.com