Skip to content

Commit b992406

Browse files
authored
Merge pull request #1361 from sounmind/main
[sounmind] Week 05 Solutions
2 parents e191914 + 9c588e7 commit b992406

File tree

2 files changed

+19
-39
lines changed

2 files changed

+19
-39
lines changed

maximum-depth-of-binary-tree/sounmind.js

-39
This file was deleted.
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from typing import Optional
2+
3+
4+
class TreeNode:
5+
def __init__(self, val=0, left=None, right=None):
6+
self.val = val
7+
self.left = left
8+
self.right = right
9+
10+
11+
class Solution:
12+
def maxDepth(self, root: Optional[TreeNode]) -> int:
13+
if not root:
14+
return 0
15+
16+
left_depth = self.maxDepth(root.left)
17+
right_depth = self.maxDepth(root.right)
18+
19+
return 1 + max(left_depth, right_depth)

0 commit comments

Comments
 (0)