mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
Update bst_lowest_common_ancestor.py
This commit is contained in:
parent
6f312b7631
commit
f8dc224ae5
@ -2,14 +2,14 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# author: bt3gl
|
||||
|
||||
def lca(self, root, p, q):
|
||||
|
||||
node = root
|
||||
this_lcw = root.val
|
||||
|
||||
def lowest_common_ancestor(root, p, q):
|
||||
|
||||
node, result = root, root
|
||||
|
||||
while node:
|
||||
|
||||
this_lcw = node
|
||||
result = node
|
||||
|
||||
if node.val > p.val and node.val > q.val:
|
||||
node = node.left
|
||||
@ -20,4 +20,4 @@
|
||||
else:
|
||||
break
|
||||
|
||||
return this_lcw
|
||||
return result
|
||||
|
Loading…
x
Reference in New Issue
Block a user