Leetcode 1927 Solution

This article provides solution to leetcode question 1927 (maximum-ascending-subarray-sum)

https://leetcode.com/problems/maximum-ascending-subarray-sum

Solution

class Solution:
    def maxAscendingSum(self, nums: List[int]) -> int:
        ans = 0
        curr_sum = 0
        last_val = -1

        for num in nums:
            if num > last_val:
                curr_sum += num
            else:
                curr_sum = num

            ans = max(curr_sum, ans)

            last_val = num

        return ans