Posted on 2023-06-19 16:27
Uriel 阅读(39)
评论(0) 编辑 收藏 引用 所属分类:
闲来无事重切Leet Code 、
大水题
求一个数列的prefix sum的最大值,水题
1 #1732
2 #Runtime: 26 ms (Beats 22.90%)
3 #Memory: 13.3 MB (Beats 78.32%)
4
5 class Solution(object):
6 def largestAltitude(self, gain):
7 """
8 :type gain: List[int]
9 :rtype: int
10 """
11 ans = 0
12 for i in range(0, len(gain)):
13 if i > 0:
14 gain[i] = gain[i - 1] + gain[i]
15 ans = max(ans, gain[i])
16 return ans