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;

    }
};



posted @ 2018-08-04 23:24  一条图图犬  阅读(288)  评论(0编辑  收藏  举报