LetCode 118. 杨辉三角

class Solution {
public:
    vector<vector<int>> generate(int numRows) {
        if (numRows <= 0)
            return vector<vector<int>>();
        vector<vector<int>> res(1, vector<int>(1,1));
        for (int i = 1; i < numRows; i++){
            vector<int> tmp;
            tmp.push_back(1);
            for (int j = 1; j < i; j++)
                tmp.push_back(res[res.size() - 1][j - 1] + res[res.size() - 1][j]);
            tmp.push_back(1);
            res.push_back(tmp);
        }
        return res;
    }
};

static int x=[](){
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    return 0;
}();

 

    原文作者:杨辉三角问题
    原文地址: https://blog.csdn.net/wbb1997/article/details/81089416
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞