@@ -0,0 +1,1442 @@
+/**%0A * Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.%0A *%0A * According to the definition of LCA on Wikipedia: %E2%80%9CThe lowest common ancestor is defined between two nodes v and w as%0A * the lowest node in T that has both v and w as descendants (where we allow a node to be a descendant of itself).%E2%80%9D%0A *%0A *            _______6______%0A *           /              %5C%0A *       ___2__          ___8__%0A *      /      %5C        /      %5C%0A *     0      _4       7       9%0A *           /  %5C%0A *          3   5%0A *%0A * For example, the lowest common ancestor (LCA) of nodes 2 and 8 is 6.%0A *%0A * Another example is LCA of nodes 2 and 4 is 2, since a node can be a descendant of itself according to the LCA definition.%0A *%0A * Tags: Tree%0A *%0A * Similar Problems: (M) Lowest Common Ancestor of a Binary Tree%0A */%0Apublic class LowestCommonAncestorOfBST %7B%0A%0A    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) %7B%0A        while (root != null) %7B%0A            if (root.val %3C p.val && root.val %3C q.val) %7B%0A                root = root.right;%0A            %7D else if (root.val %3E p.val && root.val %3E q.val) %7B%0A                root = root.left;%0A            %7D else %7B%0A                return root;%0A            %7D%0A        %7D%0A        return null;%0A    %7D%0A%0A    public class TreeNode %7B%0A%0A        int val;%0A        TreeNode left;%0A        TreeNode right;%0A%0A        TreeNode(int x) %7B%0A            val = x;%0A        %7D%0A    %7D%0A%0A%7D%0A

add 235 LCA of BST