class Solution {
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
if(root==null||root==p||root==q) return root;
TreeNode Lnode = lowestCommonAncestor(root.left, p, q);
TreeNode Rnode = lowestCommonAncestor(root.right, p, q);
if(Lnode==null&&Rnode==null) return null;
if(Lnode==null) return Rnode;
if(Rnode==null) return Lnode;
return root;
}
}



