Skip to content

Commit 902e43d

Browse files
committedFeb 9, 2019
Pascal's triangle solution
1 parent 718c1fc commit 902e43d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
 

‎118_pascal's_triangle.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def generate(self, numRows):
3+
"""
4+
:type numRows: int
5+
:rtype: List[List[int]]
6+
"""
7+
result = []
8+
for i in range(numRows):
9+
result.append([0] * (i + 1))
10+
for i in range(numRows):
11+
for j in range(i + 1):
12+
if j == 0 or j == i:
13+
result[i][j] = 1
14+
else:
15+
result[i][j] = result[i - 1][j - 1] + result[i - 1][j]
16+
return result

0 commit comments

Comments
 (0)