Skip to content

Commit 18aee37

Browse files
author
Parth Shah
authored
#235
1 parent 705fce9 commit 18aee37

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode:
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.left = None
6+
# self.right = None
7+
8+
class Solution:
9+
def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':
10+
if p.val > root.val and q.val > root.val:
11+
return self.lowestCommonAncestor(root.right,p,q)
12+
elif p.val < root.val and q.val < root.val:
13+
return self.lowestCommonAncestor(root.left,p,q)
14+
else:
15+
return root

0 commit comments

Comments
 (0)