LeetCode 98: Valid Binary Search Tree

Posted keepshuatishuati

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode 98: Valid Binary Search Tree相关的知识,希望对你有一定的参考价值。

This answer is so awesome!!

 

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    Integer min = null;
    public boolean isValidBST(TreeNode root) {
       if (root == null) {
           return true;
       }
        
        if (isValidBST(root.left) && (min == null || min < root.val)) {
            min = root.val;
            return isValidBST(root.right);
        }
        return false;
    }
}

 

以上是关于LeetCode 98: Valid Binary Search Tree的主要内容,如果未能解决你的问题,请参考以下文章

[Lintcode]95. Validate Binary Search Tree/[Leetcode]98. Validate Binary Search Tree

Leetcode 98. Validate Binary Search Tree

leetcode 98 - Validate Binary Search Tree

Leetcode 98. Validate Binary Search Tree

leetcode [98]Validate Binary Search Tree

LeetCode 98. Validate Binary Search Tree