@@ -0,0 +1,1293 @@
+/*%0A * Key point: dfs, pass the range for child's value down%0A * %0A *   A common mistake is Assume that the current node%E2%80%99s value is k. %0A *   Then for each node, check if the left node%E2%80%99s value is %0A *   less than k and the right node%E2%80%99s value is greater than k. %0A *   If all of the nodes satisfy this property, then it is a BST.%0A *%0A * Lesson: max and min int in Java is Integer.MAX_VALUE and Integer.MIN_VALUE%0A */%0A%0A/**%0A * Definition for binary tree%0A * public class TreeNode %7B%0A *     int val;%0A *     TreeNode left;%0A *     TreeNode right;%0A *     TreeNode(int x) %7B val = x; %7D%0A * %7D%0A */%0Apublic class Solution %7B%0A    public boolean isValidBST(TreeNode root) %7B%0A        if(root == null)%7B%0A            return true;%0A        %7D%0A        %0A        return dfsWorker(root, Integer.MIN_VALUE, Integer.MAX_VALUE);%0A    %7D%0A    %0A    public boolean dfsWorker(TreeNode root, int min, int max)%7B%0A        if(root.val %3C= min %7C%7C root.val %3E= max)%0A            return false;%0A            %0A        boolean leftResult = true;%0A        boolean rightResult = true;%0A        %0A        if(root.left != null)%0A            leftResult = dfsWorker(root.left, min, root.val);%0A            %0A        if(root.right != null)%0A            rightResult = dfsWorker(root.right, root.val, max);%0A            %0A        return leftResult & rightResult;%0A    %7D%0A    %0A%7D

Validate Binary Search Tree