leetcode 128 杨辉三角

土方法,找规律,效率一般,但还是要记录一下,贴代码

class Solution {
public:
    vector<vector<int>> generate(int numRows) 
    {
        vector<vector<int>> good;
        vector<int> temp;
        temp.push_back(1);
        good.push_back(temp);
        for(int i = 2 ; i <=numRows ; i++)
        {
            vector<int> temp;
            temp.push_back(1);
            for(int j = 1 ; j< i-1 ; j++)
            {
                temp.push_back(good[i-2][j-1]+good[i-2][j]);
            }
            temp.push_back(1);
            good.push_back(temp);
        }
        return good;
    }
};

这东西居然还是二项式系数排列的说法,有点东西的。

posted @ 2021-03-27 15:23  zhaohhhh  阅读(32)  评论(0)    收藏  举报