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