Leetcode 118 Pascal Triangle
class Solution:
def generate(self, numRows: int) -> List[List[int]]:
res = [[1]]
for i in range(1, numRows):
row = [1] + [res[-1][j-1] + res[-1][j] for j in range(1,i)] + [1]
res.append(row)
return res
Last posted
Total of 3 posts
Leetcode 118 Pascal Triangle
class Solution:
def generate(self, numRows: int) -> List[List[int]]:
res = [[1]]
for i in range(1, numRows):
row = [1] + [res[-1][j-1] + res[-1][j] for j in range(1,i)] + [1]
res.append(row)
return res
ผิด ๆ ต้องอันนี้
res = [[1]]
for i in range (1, numRows):
begin = [1]
end = [1]
last = res[-1]
middle = [last[j-1] + last[j] for j in range(1, len(last))]
row = [1] + middle + [1]
res.append(row)
return res
Be Civil — "Be curious, not judgemental"
All contents are responsibility of its posters.