119. Pascal's Triangle II

rowIndex=0 -> len = 1

所以 例如 rowIndex=3

1.初始化 res=[0,0,0,0],res[0]=1

res = [1,0,0,0]

2.从后往前加,循环 rowIndex-1 次,当前位=当前位+前一位

[1,0,0,0]

[1(不变),1(=1+0),0,0] = [1,1,0,0]

[1(不变),2(=1+1),1(=1+0),0] = [1,2,1,0]

[1(不变),3(=1+2),3(=2+1),1(=1+0)] = [1,3,3,1]

代码参考

 1 class Solution {
 2 public:
 3     vector<int> getRow(int rowIndex) {
 4         vector<int> res(rowIndex+1, 0);
 5         res[0]=1;
 6         for(int i=0; i<=rowIndex; i++){
 7             for(int j=i; j>0; j--){
 8                 res[j]+=res[j-1];
 9             }
10         }
11         return res;
12     }
13 };
原文地址:https://www.cnblogs.com/habibah-chang/p/12316626.html