#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
vector<int> getRow(int rowIndex)
{
int k = rowIndex + 1;
int *t = new int[k];
memset(t, 0, sizeof(int) * k);
t[0] = 1;
for(int j = 0; j < rowIndex; ++j)
{
for(int i = rowIndex; i > 0; --i)
{
t[i] = t[i] + t[i - 1];
}
}
vector<int> v(t, t+k);
delete[] t;
return v;
}
void print(vector<int> &v)
{
int len = v.size();
for(int i = 0; i < len; ++i)
cout << v[i] << " ";
cout << endl;
}
};
int main(void)
{
Solution s;
vector<int> v = s.getRow(2);
s.print(v);
return 0;
}
Pascal's Triangle 2
最新推荐文章于 2024-06-05 14:21:17 发布