GoConqr has a new look! Let us know what you think.

Flashcards

Lowest Common Ancestor

Suhas S English 1 card

Cards in this deck (1)

  1. 1LCAclass Solution:
    def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':
    # Recursive
    # if root.val >= min(p.val, q.val) and root.val <= max(p.val, q.val):
    # return root
    # node = root
    # if q.val>node.val and p.val>node.val:
    # return self.lowestCommonAncestor(root.right,p,q)
    # elif q.val= min(p.val, q.val) and root.val <= max(p.val, q.val):
    return root
    elif root.val < min(p.val, q.val):
    root = root.right
    else:
    root = root.left

Information

Description
Flashcards on Lowest Common Ancestor, created by Suhas S on 09/09/2019.
Created by
Suhas S
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?