楊輝三角 II
- 給定一個(gè)非負(fù)索引 k,其中 k ≤ 33,返回楊輝三角的第 k 行。
- 在楊輝三角中,每個(gè)數(shù)是它左上方和右上方的數(shù)的和。
class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int>res(rowIndex+1,0);
res[0]=1;
for(int i=0;i<=rowIndex;i++)
{
for(int j=i;j>0;j--)
res[j]=res[j-1]+res[j];
}
return res;
}
};