Binary Search Tree Validation
Given a binary tree root
, return whether it’s a binary search tree. A binary tree node
is a binary search tree if :
- All nodes on its left subtree are smaller than
node.val
- All nodes on its right subtree are bigger than
node.val
- All nodes hold the these properties.
Constraint
n ≤ 100,000
wheren
is the number of nodes inroot
https://binarysearch.com/problems/Binary-Search-Tree-Validation
Examples
Example 1
Input
- root =
Output
- answer =
False
Explanation
This is not a binary search tree because the 7
is not smaller than 5
.
Example 2
Input
- root =
Output
- answer =
True
Leave a comment