LeetCode 938. Range Sum of BST in F#
URL
leetcode.com/problems/range-sum-of-bst/desc..
Code
github.com/syohex/dotnet-study/blob/master/..
type Tree =
| Leaf
| Node of int * Tree * Tree
let rangeSumBST (root: Tree) (low: int) (high: int) : int =
let rec rangeSumBST' node low high acc =
match node with
| Leaf -> acc
| Node(v, left, right) ->
let acc' = if v >= low && v <= high then acc + v else acc
let acc'' = rangeSumBST' left low high acc'
rangeSumBST' right low high acc''
rangeSumBST' root low high 0