Skip to content

Commit 1ccb196

Browse files
committed
adding solutions
1 parent 57bd1a7 commit 1ccb196

3 files changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from typing import List, Union, Collection, Mapping, Optional
2+
from abc import ABC, abstractmethod
3+
4+
5+
class TreeNode:
6+
def __init__(self, val=0, left=None, right=None):
7+
self.val = val
8+
self.left = left
9+
self.right = right
10+
11+
12+
class Solution:
13+
def maxDepth(self, root: Optional[TreeNode]) -> int:
14+
15+
if not root:
16+
return 0
17+
else:
18+
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_15\
3+
.maximum_depth_tree import TreeNode, Solution
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)
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_15\
3+
.valid_parentheses import Solution
4+
5+
class ValidParenthesesTestCase(unittest.TestCase):
6+
7+
def test_is_valid_parentheses(self):
8+
solution = Solution()
9+
output = solution.isValid(s='()')
10+
self.assertTrue(output)
11+
12+
def test_is_no_valid_parentheses_pattern_1(self):
13+
solution = Solution()
14+
output = solution.isValid(s='(]')
15+
self.assertFalse(output)
16+
17+
def test_is_no_valid_parentheses_pattern_2(self):
18+
solution = Solution()
19+
output = solution.isValid(s='((')
20+
self.assertFalse(output)

0 commit comments

Comments
 (0)