Skip to content

Commit a416264

Browse files
committed
236
1 parent e895144 commit a416264

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def lowest_common_ancestor(root, p, q)
2+
return root if root.val == p.val || root.val == q.val
3+
return root if root.val.between?(p.val, q.val) || root.val.between?(q.val, p.val)
4+
5+
if root.val > p.val
6+
lowest_common_ancestor(root.left, p, q)
7+
else
8+
lowest_common_ancestor(root.right, p, q)
9+
end
10+
end

0 commit comments

Comments
 (0)