80: Validate binary search tree
Given a binary tree
, check is this a binary search tree
Binary search tree is defined as:
left
subtree of a node contains only nodes with valuesless
than theparent
valueright
subtree of a node contains only nodes with valuesgreater
than theparent
valueleft and right
subtrees must bebinary search trees
Example 1
Input: 4
/ \
3 5
Output: true
Example 2
Input: 4
/ \
3 2
Output: false
Helpful article