LeetCode 98. Validate Binary Search Tree
原题链接在这里: https://leetcode.com/problems/validate-binary-search-tree/ 题目: 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. 题解: 根据BST特性递归调用原函数,如果出现root.val >= max 或者root.val <= min的情况return false. Note: 初始的max 和 min 要设成long 型的最大最小值,因为边界的corner case. 若是用Integer.MAX_VALUE. 并且数只有一个节点,刚开始若root.val = Integer