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
最新推荐文章于 2024-11-14 20:04:48 发布