You are viewing a single comment's thread. Return to all comments →
Python sol applying BFS iterative algorithm:
import collections def height(root): q = collections.deque([root]) res = 0 visited = set() while q: n = len(q) res += 1 for i in range(n): node = q.popleft() if node and node.info not in visited: visited.add(node.info) q.append(node.left) q.append(node.right) return res - 2
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 →
Python sol applying BFS iterative algorithm: