from publicmatt.leet import TreeNode
def dfs(root: TreeNode) -> int:
if root is None:
return 0
return 1 + max(dfs(root.left), dfs(root.right))
def bfs(root: TreeNode) -> int:
from collections import deque
level = 0
q = deque()
if root is not None:
q.append(root)
while q:
count = len(q)
for _ in range(count):
node = q.popleft()
if node.left is not None:
q.append(node.left)
if node.right is not None:
q.append(node.right)
level += 1
return level