Skip to content

Commit a604816

Browse files
Solve : Maximum Depth of Binary Tree - BFS
1 parent c2bc5b7 commit a604816

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from collections import deque
2+
3+
class Solution:
4+
def maxDepth(self, root):
5+
if not root:
6+
return 0
7+
8+
queue = deque([root])
9+
depth = 0
10+
11+
while queue:
12+
for _ in range(len(queue)):
13+
node = queue.popleft()
14+
if node.left:
15+
queue.append(node.left)
16+
if node.right:
17+
queue.append(node.right)
18+
depth += 1
19+
20+
return depth

0 commit comments

Comments
 (0)