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 3887c3b commit ec3553fCopy full SHA for ec3553f
maximum-depth-of-binary-tree/aa601.py
@@ -0,0 +1,12 @@
1
+'''
2
+TC: O(n)
3
+SC: O(n)
4
5
+
6
+class Solution:
7
+ def maxDepth(self, root: Optional[TreeNode]) -> int:
8
+ # 재귀함수 호출 시 노드가 존재하지 않을 때 탈출한다
9
+ if not root:
10
+ return 0
11
+ # root를 기준으로 왼쪽 서브트리, 오른쪽 서브트리를 재귀호출로 쌓아놓고 리프노드부터 세면서 트리의 깊이를 구한다
12
+ return max(self.maxDepth(root.left), self.maxDepth(root.right)) + 1
0 commit comments