Solve 104, 118, 28

This commit is contained in:
Kiril Kovachev 2024-04-30 16:56:00 +01:00
parent cef4a48ca9
commit 099bac4380
3 changed files with 12 additions and 0 deletions

View File

@ -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

View File

@ -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