leetcode119 C++ 0ms 杨辉三角2

class Solution {
public:
    vector<int> getRow(int rowIndex) {
        rowIndex++;
        if(rowIndex<=0){
            return {};
        }
        else if(rowIndex==1){
            return {1};
        }
        vector<int> res(rowIndex, 0);
        res[0] = 1;
        vector<int> curr = res;
        for(int i=1;i<rowIndex+1;i++){
            for( int j=1;j<i;j++){
                res[j] = curr[j-1] + curr[j];
            }
            curr = res;
        }
        return res;

    }
};



原文地址:https://www.cnblogs.com/theodoric008/p/9420597.html