less than 1 minute read

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 where n is the number of nodes in root

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

Solution

Leave a comment