@@ -0,0 +1,1516 @@
+/**%0A * Definition for a binary tree node.%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 TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) %7B%0A        if(root == null)%7B%0A            return null;%0A        %7D%0A        if((root == p && containNode(root, q)) %7C%7C (root == q && containNode(root, p)))%7B%0A            return root;%0A        %7Delse if((containNode(root.left, p) && containNode(root.right, q)) %7C%7C (containNode(root.left, q) && containNode(root.right, p)))%7B%0A            return root;%0A        %7Delse if(containNode(root.left, p) && containNode(root.left, q))%7B%0A            return lowestCommonAncestor(root.left, p, q);%0A        %7Delse if(containNode(root.right, p) && containNode(root.right, q))%7B%0A            return lowestCommonAncestor(root.right, p, q);%0A        %7Delse%7B%0A            return null;%0A        %7D%0A    %7D%0A    %0A    private boolean containNode(TreeNode root, TreeNode p)%7B%0A        if(root == null)%7B%0A            return false;%0A        %7Delse if(root == p)%7B%0A            return true;%0A        %7Delse if(root.left == null && root.right == null)%7B%0A            return false;%0A        %7Delse if(root.left != null && root.right == null)%7B%0A            return containNode(root.left, p);%0A        %7Delse if(root.left == null && root.right != null)%7B%0A            return containNode(root.right, p);%0A        %7Delse%7B%0A            return containNode(root.left, p) %7C%7C containNode(root.right, p);%0A        %7D%0A    %7D%0A%7D

Q235 Lowest Common Ancestor of a Binary Search Tree