LeetCode 2485. Find the Pivot Integer in F#

URL

Find the Pivot Integer - LeetCode

Code

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

let pivotInteger (n: int) : int =
    let rec pivotInteger' i n sum total =
        if i > n then
            -1
        else
            let sum' = sum + i

            if sum' = total - sum then
                i
            else
                pivotInteger' (i + 1) n sum' total

    let total = (1 + n) * n / 2
    pivotInteger' 1 n 0 total