LeetCode 1614. Maximum Nesting Depth of the Parentheses in F#

URL

https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/description/?envType=daily-question&envId=2024-04-04

Code

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

let maxDepth (s: string) : int =
    let rec maxDepth' cs depth ret =
        match cs with
        | [] -> ret
        | h :: t ->
            match h with
            | '(' -> maxDepth' t (depth + 1) (System.Math.Max(ret, depth + 1))
            | ')' -> maxDepth' t (depth - 1) ret
            | _ -> maxDepth' t depth ret

    maxDepth' (Seq.toList s) 0 0