From 099bac4380822627ea130653a07861aae8771bbd Mon Sep 17 00:00:00 2001 From: Kiril Kovachev Date: Tue, 30 Apr 2024 16:56:00 +0100 Subject: [PATCH] Solve 104, 118, 28 --- python/104_maximum_depth_of_binary_tree.py | 5 +++++ python/118_pascals_triangle.py | 7 +++++++ ..._find_the_index_of_the_first_occurrence_in_a_string.py} | 0 3 files changed, 12 insertions(+) create mode 100644 python/104_maximum_depth_of_binary_tree.py create mode 100644 python/118_pascals_triangle.py rename python/{28_find_the_index_of_the_first_occurrence_in_a_string => 28_find_the_index_of_the_first_occurrence_in_a_string.py} (100%) diff --git a/python/104_maximum_depth_of_binary_tree.py b/python/104_maximum_depth_of_binary_tree.py new file mode 100644 index 0000000..06f9f84 --- /dev/null +++ b/python/104_maximum_depth_of_binary_tree.py @@ -0,0 +1,5 @@ +class Solution: + def maxDepth(self, root: Optional[TreeNode]) -> int: + if root is None: + return 0 + return max(self.maxDepth(root.left), self.maxDepth(root.right)) + 1 diff --git a/python/118_pascals_triangle.py b/python/118_pascals_triangle.py new file mode 100644 index 0000000..c763227 --- /dev/null +++ b/python/118_pascals_triangle.py @@ -0,0 +1,7 @@ +class Solution: + def generate(self, numRows: int) -> List[List[int]]: + rows = [] + for i in range(1, numRows + 1): + row = [1 if j == 0 or j >= i - 1 else rows[i-2][j-1]+rows[i-2][j] for j in range(i)] + rows.append(row) + return rows diff --git a/python/28_find_the_index_of_the_first_occurrence_in_a_string b/python/28_find_the_index_of_the_first_occurrence_in_a_string.py similarity index 100% rename from python/28_find_the_index_of_the_first_occurrence_in_a_string rename to python/28_find_the_index_of_the_first_occurrence_in_a_string.py