Skip to content

Commit

Permalink
帕斯卡三角形
Browse files Browse the repository at this point in the history
  • Loading branch information
rinwf committed Sep 23, 2018
1 parent a0285ec commit 4d10ade
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lc118. Pascal's Triangle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class Solution:
def generate(self, numRows):
"""
:type numRows: int
:rtype: List[List[int]]
"""
if not numRows:
return []
# elif numRows == 1:
# return [[1]]
# elif numRows == 2:
# return [[1], [1, 1]]

# res = [[1], [1, 1]]
res = [[1]]

for i in range(1, numRows):
tem = []
tem.append(1)

for j in range(1, i):

x = res[i - 1][j] + res[i - 1][j - 1]
tem.append(x)
tem.append(1)
res.append(tem)

return res


num = 5
s = Solution()
print(s.generate(num))

0 comments on commit 4d10ade

Please sign in to comment.