LeetCode 2419. Longest Subarray With Maximum Bitwise AND in F#

URL

https://leetcode.com/problems/longest-subarray-with-maximum-bitwise-and/description/?envType=daily-question&envId=2024-09-14

Code

https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/challenge/202409/longest_subarray_with_maximum_bitwise_and/main.fsx

let longestSubArray (nums: int list) : int =
    let rec longestSubArray' nums maxVal len acc =
        match nums with
        | [] -> acc
        | h :: t ->
            let maxVal, len, acc = if h > maxVal then h, 0, 0 else maxVal, len, acc

            if h = maxVal then
                let len = len + 1
                longestSubArray' t maxVal len (max acc len)
            else
                longestSubArray' t maxVal 0 acc

    longestSubArray' nums 0 0 0