We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def height(root):
left = root.left
right = root.right
if left == None and right == None:
return 0
r_ht, l_ht = 0, 0
if left!=None:
l_ht = height(left)
if right!=None:
r_ht = height(right)
return 1+max(r_ht,l_ht)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Height of a Binary Tree
You are viewing a single comment's thread. Return to all comments →
def height(root): left = root.left right = root.right if left == None and right == None: return 0 r_ht, l_ht = 0, 0 if left!=None: l_ht = height(left) if right!=None: r_ht = height(right) return 1+max(r_ht,l_ht)