天天看點

pascals-triangle-ii

題目:

Given an index k, return the k th row of the Pascal’s triangle.

For example, given k = 3,

Return[1,3,3,1].

Note:

Could you optimize your algorithm to use only O(k) extra space?

程式:

class Solution {
public:
    vector<int> getRow(int rowIndex) {
         vector<int> dp(rowIndex+,);
         dp[]=;
         for(int i=;i<=rowIndex;i++)
             for(int j=i;j>=;j--)
                 dp[j]+=dp[j-];
         return dp;
     }
};