| 63 | # self.right = None |
| 64 | |
| 65 | class Solution(object): |
| 66 | def lowestCommonAncestor(self, root, p, q): |
| 67 | """ |
| 68 | :type root: TreeNode |
| 69 | :type p: TreeNode |
| 70 | :type q: TreeNode |
| 71 | :rtype: TreeNode |
| 72 | """ |
| 73 | if root.val == p.val or root.val == q.val: |
| 74 | return root |
| 75 | |
| 76 | right = None |
| 77 | left = None |
| 78 | |
| 79 | if root.right: |
| 80 | right = self.lowestCommonAncestor(root.right, p, q) |
| 81 | if root.left: |
| 82 | left = self.lowestCommonAncestor(root.left, p, q) |
| 83 | |
| 84 | if right and left: |
| 85 | return root |
| 86 | |
| 87 | if right: |
| 88 | return right |
| 89 | |
| 90 | if left: |
| 91 | return left |
nothing calls this directly
no outgoing calls
no test coverage detected