Maximum Depth of Binary Tree

https://leetcode.com/problems/maximum-depth-of-binary-tree/

Solution 1: Recursion

if not root:
    return 0
return 1 + max(maxDepth(root.left), maxDepth(root.right))

Solution 2: Tail Recursion + BFS

Solution 3: Iteration

Also implements bfs, while keeping track of maximum depth encountered so far.

stack = []
if root is not None:
    stack.append((1, root))
 
depth = 0
while stack != []:
    current_depth, root = stack.pop()
    if root is not None:
        depth = max(depth, current_depth)
        stack.append((current_depth + 1, root.left))
        stack.append((current_depth + 1, root.right))
 
return depth