The approach I take is perform a post order traversal and at the last check if the current node is equivalent to one of the nodes given in parameter. I soon increment if I find a node and if I have found all two, I just paste the current node in a variable and keep on returning. Please let me know if you find anything wrong in my implementation. I think the running time here should be O(n) and space complexity should be O(h) where h is the height of the tree.

```
public class Solution {
int numVal=0;
TreeNode found = null;
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
if(root==null)
return null;
findLCA(root,p,q);
return null;
}
public void findLCA(TreeNode root, TreeNode p, TreeNode q){
if(root==null)
return;
findLCA(root.left,p,q);
if(numVal==2)
return;
findLCA(root.right,p,q);
if(numVal==2)
return;
if(root==p )
numVal++;
else if(root==q)
numVal++;
if(numVal==2)
found = root;
}
}
```