您的位置:首页 > 其它

LeetCode-Pascal's Triangle II

2013-08-16 18:05 302 查看
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;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: