LeetCode 1800. Maximum Ascending Subarray Sum in F#
URL
Maximum Ascending Subarray Sum - LeetCode
Code
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