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 caa6e7c commit 9984366Copy full SHA for 9984366
maximum-depth-of-binary-tree/sejineer.py
@@ -0,0 +1,19 @@
1
+"""
2
+시간 복잡도: O(N)
3
+공간 복잡도: O(h) h = 트리 높이
4
5
+class Solution:
6
+ def maxDepth(self, root: Optional[TreeNode]) -> int:
7
+ result = 0
8
+
9
+ def dfs(tree: Optional[TreeNode], depth: int):
10
+ nonlocal result
11
+ if tree == None:
12
+ result = max(result, depth)
13
+ return
14
15
+ dfs(tree.left, depth + 1)
16
+ dfs(tree.right, depth + 1)
17
18
+ dfs(root, 0)
19
+ return result
0 commit comments