mirror of
				https://github.com/autistic-symposium/master-algorithms-py.git
				synced 2025-11-03 22:54:02 -05:00 
			
		
		
		
	Update bst_lowest_common_ancestor.py
This commit is contained in:
		
							parent
							
								
									6f312b7631
								
							
						
					
					
						commit
						f8dc224ae5
					
				
					 1 changed files with 6 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -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…
	
	Add table
		Add a link
		
	
		Reference in a new issue