We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c2bc5b7 commit a604816Copy full SHA for a604816
maximum-depth-of-binary-tree/printjin-gmailcom.py
@@ -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