0
点赞
收藏
分享

微信扫一扫

LeetCode题解(1798):你能构造出连续值的最大数目(Python)


题目:​​原题链接​​(中等)

标签:排序、贪心算法

解法

时间复杂度

空间复杂度

执行用时

Ans 1 (Python)

152ms (55.26%)

Ans 2 (Python)

Ans 3 (Python)

解法一:

class Solution:
def getMaximumConsecutive(self, coins: List[int]) -> int:
coins.sort()
now = 0
for coin in coins:
if coin > now + 1:
return now + 1
else:
now += coin
return now + 1


举报

相关推荐

0 条评论