From 1ccb19697f6c88983f5f9db2619e3e41681a0c1c Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 17 Apr 2025 04:24:10 -0600 Subject: [PATCH] adding solutions --- .../maximum_depth_tree.py | 18 +++++++++++++++++ .../test_maximum_depth_tree_round_15.py | 20 +++++++++++++++++++ .../test_valid_parentheses_round_15.py | 20 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_15/maximum_depth_tree.py create mode 100644 tests/test_150_questions_round_15/test_maximum_depth_tree_round_15.py diff --git a/src/my_project/interviews/top_150_questions_round_15/maximum_depth_tree.py b/src/my_project/interviews/top_150_questions_round_15/maximum_depth_tree.py new file mode 100644 index 00000000..dd432797 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_15/maximum_depth_tree.py @@ -0,0 +1,18 @@ +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 \ No newline at end of file diff --git a/tests/test_150_questions_round_15/test_maximum_depth_tree_round_15.py b/tests/test_150_questions_round_15/test_maximum_depth_tree_round_15.py new file mode 100644 index 00000000..e09b42e5 --- /dev/null +++ b/tests/test_150_questions_round_15/test_maximum_depth_tree_round_15.py @@ -0,0 +1,20 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_15\ +.maximum_depth_tree import TreeNode, Solution + + +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) \ No newline at end of file diff --git a/tests/test_150_questions_round_15/test_valid_parentheses_round_15.py b/tests/test_150_questions_round_15/test_valid_parentheses_round_15.py index e69de29b..75a507d5 100644 --- a/tests/test_150_questions_round_15/test_valid_parentheses_round_15.py +++ b/tests/test_150_questions_round_15/test_valid_parentheses_round_15.py @@ -0,0 +1,20 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_15\ +.valid_parentheses import Solution + +class ValidParenthesesTestCase(unittest.TestCase): + + def test_is_valid_parentheses(self): + solution = Solution() + output = solution.isValid(s='()') + self.assertTrue(output) + + def test_is_no_valid_parentheses_pattern_1(self): + solution = Solution() + output = solution.isValid(s='(]') + self.assertFalse(output) + + def test_is_no_valid_parentheses_pattern_2(self): + solution = Solution() + output = solution.isValid(s='((') + self.assertFalse(output) \ No newline at end of file