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.
Tree: Height of a Binary Tree
Tree: Height of a Binary Tree
Sort by
recency
|
985 Discussions
|
Please Login in order to post a comment
Solution in Java:
Swift is in fact broken. The boilerplate provided is causing issue even with correct code in the getHeight() function. The boilerplate provided is force-unwrapping data in an unsafe way causing the issue to occur during the construction of the tree - even before our user controlled code can execute. Leetcode never has this issue.
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)
Javascript testing doesn't work. Do not waste time on it.
swift broken, returning 0 with no logic will still crash with unwrapping nil.