LeetCode 98. Validate Binary Search Tree in F#
URL
leetcode.com/problems/validate-binary-searc..
Code
github.com/syohex/dotnet-study/blob/master/..
open System
type Tree =
| Leaf
| Node of int64 * Tree * Tree
let isValidBST (root: Tree) : bool =
let rec isValidBST' node (min: int64) (max: int64) =
match node with
| Leaf -> true
| Node (v, left, right) ->
if v <= min || v >= max then
false
else
isValidBST' left min v && isValidBST' right v max
isValidBST' root Int32.MinValue Int32.MaxValue