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