Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 48151fa

Browse files
#118 Pascal's Triangle
1 parent af16a4a commit 48151fa

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

‎Array/pascals-triangle.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from itertools import pairwise
2+
from typing import List
3+
4+
class Solution:
5+
def generate(self, numRows: int) -> List[int[int]]:
6+
pascal = [[1]]
7+
8+
for i in range(numRows - 1):
9+
x = [1] + [a+b for a, b in pairwise(pascal[-1])] + [1]
10+
pascal.append(x)
11+
return pascal

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /