Skip to content

Commit 1aaece7

Browse files
committed
[LeetCode Sync] Runtime - 0 ms (100.00%), Memory - 17.7 MB (81.68%)
1 parent 2461254 commit 1aaece7

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal&#39;s triangle</strong>.</p>
2+
3+
<p>In <strong>Pascal&#39;s triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
4+
<img alt="" src="https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAnimated2.gif" style="height:240px; width:260px" />
5+
<p>&nbsp;</p>
6+
<p><strong class="example">Example 1:</strong></p>
7+
<pre><strong>Input:</strong> rowIndex = 3
8+
<strong>Output:</strong> [1,3,3,1]
9+
</pre><p><strong class="example">Example 2:</strong></p>
10+
<pre><strong>Input:</strong> rowIndex = 0
11+
<strong>Output:</strong> [1]
12+
</pre><p><strong class="example">Example 3:</strong></p>
13+
<pre><strong>Input:</strong> rowIndex = 1
14+
<strong>Output:</strong> [1,1]
15+
</pre>
16+
<p>&nbsp;</p>
17+
<p><strong>Constraints:</strong></p>
18+
19+
<ul>
20+
<li><code>0 &lt;= rowIndex &lt;= 33</code></li>
21+
</ul>
22+
23+
<p>&nbsp;</p>
24+
<p><strong>Follow up:</strong> Could you optimize your algorithm to use only <code>O(rowIndex)</code> extra space?</p>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def getRow(self, rowIndex: int) -> List[int]:
3+
dp = [1] * (rowIndex + 1)
4+
for i in range(2, rowIndex + 1):
5+
for j in range(i - 1, 0, -1):
6+
dp[j] += dp[j - 1]
7+
8+
return dp

0 commit comments

Comments
 (0)