bfs, from collections import deque

# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

#
# 
# @param root TreeNode类 
# @return int整型
#
from collections import deque
class Solution:
    def maxDepth(self , root ):
        # write code here
        if not root:
            return 0
        q = deque([root])
        depth = 0
        while q:
            length = len(q)
            for i in range(length):
                curr = q.popleft()
                if curr.left:
                    q.append(curr.left)
                if curr.right:
                    q.append(curr.right)
            depth += 1
        return depth