1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
class Solution:
def maxAscendingSum(self, nums: List[int]) -> int:
ans=[]
tmp=0
if len(nums)== 1: ans.append(nums[0])
else :
for i in range(len(nums)-1):
if nums[i]<nums[i+1]:tmp+=nums[i]
else :
tmp += nums[i]
ans.append(tmp)
tmp=0
if i==len(nums)-2 : ans.append(tmp+nums[-1])
return max(ans)
|
cs |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 258. Add Digits (0) | 2022.04.08 |
---|---|
leetcode 1550. Three Consecutive Odds (0) | 2022.04.04 |
leetcode 896. Monotonic Array (0) | 2022.03.28 |
leetcode 1185. Day of the Week (0) | 2022.03.28 |
leetcode 448. Find All Numbers Disappeared in an Array (0) | 2022.03.28 |
댓글