Leetcode Note: Go - Maximum Ascending Subarray Sum

Maximum Ascending Subarray Sum - LeetCode
https://leetcode.com/problems/maximum-ascending-subarray-sum/

  • Go 言語で取り組んだメモ

回答

Golang O(n) solution faster than 100% with walk through - Maximum Ascending Subarray Sum - LeetCode
https://leetcode.com/problems/maximum-ascending-subarray-sum/solutions/1159788/golang-o-n-solution-faster-than-100-with-walk-through/

func maxAscendingSum(nums []int) int {
    maximum := nums[0]
    sum := nums[0]

    for i := 1; i < len(nums); i++ {
        if nums[i] > nums[i-1] {
            sum += nums[i]
        } else {
            maximum, sum = 
            int(math.Max(float64(maximum), float64(sum))), nums[i]
        }
    }
    maximum = int(math.Max(float64(maximum), float64(sum)))
    return maximum
}