1. Problem Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes with keys greater than the node's key. Both the left and right subtrees must also be binary search trees. 2. Idea An easy mistake is to make the decision by recursively compare the root with its left and right children. Even if its value is within its left child's and right child's, there is no guarantee that the above properties hold.
Read full article from LeetCode - Validate Binary Search Tree | Darren's Blog
No comments:
Post a Comment