| 55 | # self.right = None |
| 56 | |
| 57 | class Solution(object): |
| 58 | def lowestCommonAncestor(self, root, p, q): |
| 59 | """ |
| 60 | :type root: TreeNode |
| 61 | :type p: TreeNode |
| 62 | :type q: TreeNode |
| 63 | :rtype: TreeNode |
| 64 | """ |
| 65 | |
| 66 | if p.val == root.val or q.val == root.val: |
| 67 | return root |
| 68 | |
| 69 | if p.val < root.val and q.val > root.val: |
| 70 | return root |
| 71 | elif p.val > root.val and q.val < root.val: |
| 72 | return root |
| 73 | |
| 74 | if p.val > root.val and q.val > root.val: |
| 75 | |
| 76 | return self.lowestCommonAncestor(root.right, p, q) |
| 77 | |
| 78 | else: |
| 79 | return self.lowestCommonAncestor(root.left, p, q) |
| 80 |
nothing calls this directly
no outgoing calls
no test coverage detected