Solve 104, 118, 28
This commit is contained in:
parent
cef4a48ca9
commit
099bac4380
5
python/104_maximum_depth_of_binary_tree.py
Normal file
5
python/104_maximum_depth_of_binary_tree.py
Normal 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
|
7
python/118_pascals_triangle.py
Normal file
7
python/118_pascals_triangle.py
Normal 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
|
Loading…
Reference in New Issue
Block a user