######python 写的广度优先的代码
class Solution:
def maxDepth(self, root: TreeNode) -> int:
if not root: return 0
queue=[]
visited=[]
queue.append(root)
length=0
while queue:
len1=len(queue)
length+=1
for i in range(len1):
node=queue.pop(0)
if node.left:
queue.append(node.left)
if node.right:
queue.append(node.right)
return length