LeetCode 669. Trim a Binary Search Tree in F#
URL
leetcode.com/problems/trim-a-binary-search-..
Code
github.com/syohex/dotnet-study/blob/master/..
type Tree =
| Leaf
| Node of int * Tree * Tree
let rec trimBST (root: Tree) (low: int) (high: int) =
match root with
| Leaf -> Leaf
| Node (v, left, right) ->
let left' = trimBST left low high
let right' = trimBST right low high
if v >= low && v <= high then
Node(v, left', right')
else
match left' with
| Leaf -> right'
| _ -> left'