LeetCode 1800. Maximum Ascending Subarray Sum in F#

URL

Maximum Ascending Subarray Sum - LeetCode

Code

https://github.com/syohex/dotnet-study/tree/master/fsharp/leetcode/challenge/202502/maximum_ascending_subarray_sum/main.fsx

let maxAscendingSum (nums: int list) : int =
    let rec maxAscendingSum' nums prev sum acc =
        match nums with
        | [] -> acc
        | h :: t ->
            let sum = if prev < h then sum + h else h
            maxAscendingSum' t h sum (max acc sum)

    match nums with
    | [] -> failwith "never reach here"
    | h :: t -> maxAscendingSum' t h h h