LeetCode 2485. Find the Pivot Integer in F#
URL
Find the Pivot Integer - LeetCode
Code
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