(TreeNode root, TreeNode p, TreeNode q)
| 1 | class Solution { |
| 2 | public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { |
| 3 | |
| 4 | if(root == null || root == p || root == q) |
| 5 | return root; |
| 6 | |
| 7 | TreeNode left = lowestCommonAncestor(root.left, p, q); |
| 8 | TreeNode right = lowestCommonAncestor(root.right, p, q); |
| 9 | |
| 10 | if(left==null) return right; |
| 11 | else if(right==null) return left; |
| 12 | else return root; |
| 13 | |
| 14 | } |
| 15 | } |
nothing calls this directly
no outgoing calls
no test coverage detected