Skip to content

Dipin Krishna

I love to code. If you feel the same, then i have some cool codes for you. They are simple but good to get started.

  • Home
  • Blog
  • Privacy Policy
  • About
  • Contact
  • Home
  • Blog
  • Privacy Policy
  • About
  • Contact

Tag Archives: Lowest Common Ancestor

Home/Posts Tagged: Lowest Common Ancestor
python

Python: Lowest Common Ancestor of a Binary Tree – Non Recursive

Sep 23, 2018Dipin KrishnaCoding, PythonBinary Tree, LCA, Lowest Common Ancestor, Python, Python 3

Python 3 code to find the Lowest Common Ancestor of a Binary Tree This is a Non Recursive solution using DFS method. class Node(): def __init__(self, val, left = None, right = None): self.val = val self.left = left self.right = right   class Tree(): def __init__(self, root = None): self.root = root   def

Read More

python

Python: Lowest Common Ancestor of a Binary Search Tree

Sep 22, 2018Dipin KrishnaCoding, General, PythonBinary Search Tree, BST, LCA, Lowest Common Ancestor, Python, Python 3

Python 3 code to find the Lowest Common Ancestor of a Binary Search Tree def lowestCommonAncestor(root, p, q): """ :type root: TreeNode :type p: TreeNode :type q: TreeNode :rtype: TreeNode """ if root is None or p is None or q is None: return None   if p.val > q.val: temp = p p =

Read More

Search

Theme by Think Up Themes Ltd. Powered by WordPress.