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 33dc6e9 commit a5875bcCopy full SHA for a5875bc
1 file changed
maximum-depth-of-binary-tree/gcount85.py
@@ -0,0 +1,19 @@
1
+"""
2
+# Intuition
3
+1) BFS + 큐
4
+2) DFS + 재귀
5
+1번으로 풀었다가 2번이 코드가 더 간결해서 바꿨습니다.
6
+
7
+# Complexity
8
+- Time complexity: 모든 노드를 다 봐야 하므로 O(N)
9
10
+- Space complexity: 재귀 깊이만큼 O(H)
11
12
13
+class Solution:
14
+ def maxDepth(self, root: Optional[TreeNode]) -> int:
15
+ if not root:
16
+ return 0
17
+ return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))
18
19
0 commit comments