# Maximum Depth of Binary Tree

## Problem

Given the `root` of a binary tree, return *its maximum depth*.

A binary tree's **maximum depth** is the number of nodes along the longest path from the root node down to the farthest leaf node.

![](https://1063826111-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MGdx41c9p2PMgIHbUTK%2F-MNQ2Vkkv00ivore3bDu%2F-MNQ3zjt50WEfHHmAo2i%2FScreen%20Shot%202020-11-30%20at%202.34.19%20PM.png?alt=media\&token=053467c5-89d8-485e-8612-20c9432cfd0f)

## Solution

```
from collections import deque
class Solution:
    def maxDepth(self, root: TreeNode) -> int:
        if root is None:
            return 0
        
        depthCount = 0
        queue = deque()
        queue.append(root)
        
        while queue:
            depthCount+=1
            levelSize = len(queue)
            
            for _ in range(levelSize):
                currentNode = queue.popleft()
                
                if currentNode.left:
                    queue.append(currentNode.left)
                if currentNode.right:
                    queue.append(currentNode.right)
        return depthCount
        
#Time: O(n)
#Space: O(n)
```
