Skip to content

Commit 3712b81

Browse files
authored
Merge pull request #1278 from ivan1016017/may22
adding algo
2 parents 6effa59 + e1c9d63 commit 3712b81

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)