Skip to content

Commit a9a6e70

Browse files
authored
Create 119. Pascal's Triangle II.cpp
1 parent f966804 commit a9a6e70

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

119. Pascal's Triangle II.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
vector<int> getRow(int rowIndex) {
4+
vector<int> ans(rowIndex + 1);
5+
long long temp = 1;
6+
ans[0] = ans[rowIndex] = 1;
7+
8+
for (int i = 1, up = rowIndex, down = 1; i <= rowIndex; i++, up--, down++) {
9+
temp = temp * up / down;
10+
ans[i] = static_cast<int>(temp);
11+
}
12+
13+
return ans;
14+
}
15+
};

0 commit comments

Comments
 (0)