LeetCode 538. Convert BST to Greater Tree in F#

URL

leetcode.com/problems/convert-bst-to-greate..

Code

github.com/syohex/dotnet-study/blob/master/..

type Tree =
    | Leaf
    | Node of int * Tree * Tree

let convertBST (root: Tree) =
    let rec convertBST' (node: Tree) (v: int) : (Tree * int) =
        match node with
        | Leaf -> Leaf, v
        | Node (n, left, right) ->
            let (right', rMax) = convertBST' right v
            let (left', lMax) = convertBST' left (n + rMax)
            Node(n + rMax, left', right'), lMax

    let t, _ = convertBST' root 0
    t