본문 바로가기
python-algorithm

leetcode 1800. Maximum Ascending Subarray Sum

by 무적김두칠 2022. 4. 4.

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
반응형

댓글