Skip to content

Commit 9af2c94

Browse files
Solve : Lowest Common Ancestor of a Binary Search Tree
1 parent 2692e2f commit 9af2c94

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def lowestCommonAncestor(self, root, p, q):
3+
while root:
4+
if p.val < root.val and q.val < root.val:
5+
root = root.left
6+
elif p.val > root.val and q.val > root.val:
7+
root = root.right
8+
else:
9+
return root

0 commit comments

Comments
 (0)