class Solution {
public:
vector<int> getRow(int rowIndex) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector<int> ans(rowIndex + 1, 0);
ans[0] = 1;
for (int i = 0; i < rowIndex; ++i)
{
int pre = 1;
int cur;
for (int j = 1; j <= i + 1; ++j)
{
cur = ans[j];
ans[j] += pre;
pre = cur;
}
}
return ans;
}
};
LeetCode-Pascal's Triangle II
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.