Given an index k, return the kth row of the Pascal’s triangle.
class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> ANS;
ANS.push_back(1);
long long ans = 1, a = rowIndex, b = 1;
while(a >=1 )
{
ans *= a;
ans /= b;
a--; b++;
ANS.push_back((int)ans);
}
return ANS;
}
};
本文介绍了一个C++实现的方法,用于获取帕斯卡三角形中的指定行。通过迭代计算公式,该方法能够有效地得出帕斯卡三角形中任意一行的所有元素。
610

被折叠的 条评论
为什么被折叠?



