Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import List, Union, Collection, Mapping, Optional
from abc import ABC, abstractmethod

class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right

class Solution:
def maxDepth(self, root: Optional[TreeNode]) -> int:

if not root:
return 0
else:
return max(self.maxDepth(root.left), self.maxDepth(root.right)) + 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import unittest
from src.my_project.interviews.top_150_questions_round_20\
.maximum_depth_tree import Solution, TreeNode

class MaxDepthTreeTestCase(unittest.TestCase):

def test_max_depth_null(self):
solution = Solution()
tree = None
output = solution.maxDepth(root=tree)
target = 0
self.assertEqual(output, target)

def test_max_depth(self):
solution = Solution()
tree = TreeNode(1)
output = solution.maxDepth(root=tree)
target = 1
self.assertEqual(output, target)