# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
import queue
class Solution:
def maxDepth(self, root: TreeNode) -> int:
if not root:
return 0
depth = 0
q = queue.Queue()
q.put(root)
while not q.empty():
count = q.qsize()
depth += 1
for _ in range(count):
node = q.get()
if node.left:
q.put(node.left)
if node.right:
q.put(node.right)
return depth