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 2239f2d commit 1620e94Copy full SHA for 1620e94
maximum-depth-of-binary-tree/pmjuu.py
@@ -0,0 +1,22 @@
1
+'''
2
+시간 복잡도: O(n)
3
+공간 복잡도: O(n)
4
5
+from typing import Optional
6
+
7
+# Definition for a binary tree node.
8
+class TreeNode:
9
+ def __init__(self, val=0, left=None, right=None):
10
+ self.val = val
11
+ self.left = left
12
+ self.right = right
13
14
+class Solution:
15
+ def maxDepth(self, root: Optional[TreeNode]) -> int:
16
+ if not root:
17
+ return 0
18
19
+ left = self.maxDepth(root.left)
20
+ right = self.maxDepth(root.right)
21
22
+ return max(left, right) + 1
0 commit comments