Skip to content

Commit 1620e94

Browse files
committed
solve 1
1 parent 2239f2d commit 1620e94

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)