Update bst_lowest_common_ancestor.py

This commit is contained in:
bt3gl 2023-08-08 16:00:29 -07:00 committed by GitHub
parent 6f312b7631
commit f8dc224ae5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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