Pascal's Triangle

class Solution {
public:
    vector<vector<int> > generate(int numRows) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        vector<int> pre;
        vector<int> temp;
        vector<vector<int> >result;
        if(numRows<=0)
        return result;
        temp.push_back(1);
        result.push_back(temp);
        for(int i = 1;i < numRows;i++)
        {
            temp.clear();
            temp.push_back(1);
            for(int j = 1; j < i;j++)
            {
                temp.push_back(pre[j-1]+pre[j]);
            }
            temp.push_back(1);
            result.push_back(temp);
            pre = temp;
        }
        return result;
    }
};
原文地址:https://www.cnblogs.com/727713-chuan/p/3330812.html