Skip to content

Commit 64121bf

Browse files
authored
Merge pull request #1314 from ivan1016017/june26
adding algo
2 parents abcc2ab + 8747c33 commit 64121bf

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from typing import List, Union, Collection, Mapping, Optional
2+
from abc import ABC, abstractmethod
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+
14+
if not root:
15+
return 0
16+
else:
17+
return max(self.maxDepth(root.left), self.maxDepth(root.right)) + 1
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import unittest
2+
from src.my_project.interviews.top_150_questions_round_17\
3+
.maximum_depth_tree import TreeNode, Solution
4+
5+
class MaxDepthTreeTestCase(unittest.TestCase):
6+
7+
def test_max_depth_null(self):
8+
solution = Solution()
9+
tree = None
10+
output = solution.maxDepth(root=tree)
11+
target = 0
12+
self.assertEqual(output, target)
13+
14+
def test_max_depth(self):
15+
solution = Solution()
16+
tree = TreeNode(1)
17+
output = solution.maxDepth(root=tree)
18+
target = 1
19+
self.assertEqual(output, target)

0 commit comments

Comments
 (0)