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 2e059f5 commit 269516bCopy full SHA for 269516b
maximum-depth-of-binary-tree/thispath98.py
@@ -10,16 +10,18 @@ def maxDepth(self, root: Optional[TreeNode]) -> int:
10
모든 노드에 대해 재귀적으로 호출하므로 O(N)이다.
11
12
Space Complexity:
13
- O(1):
14
- answer 변수만 사용하므로 O(1)이다.
+ O(h):
+ 트리의 높이 h만큼 재귀 함수를 호출하므로,
15
+ 공간 복잡도는 O(h)이다.
16
"""
17
+
18
def get_depth(node, depth):
19
if not node:
20
return depth
21
22
left = get_depth(node.left, depth + 1)
23
right = get_depth(node.right, depth + 1)
24
return max(left, right)
-
25
26
answer = get_depth(root, 0)
27
return answer
0 commit comments