Leetcode - Pascal's Triangle

题目链接

Pascal's Triangle

Given numRows, generate the first numRows of Pascal's triangle.
For example, given numRows = 5,
Return as:

图 1-1 题目

解题思路

TODO (稍后补充)

解答代码

class Solution {
public:
    vector> generate(int numRows) {
        vector > op;
        if (numRows == 0) return op;
        vector line(numRows, 0);
        line[0]=1;
        op.push_back(vector(1,1));
        for (int i=1;i=1;k--) {
               line[k] = line[k] + line[k-1]; 
            }
            op.push_back(vector(line.begin(), line.begin()+i+1));
        }
        return op;
    }
};

你可能感兴趣的:(Leetcode - Pascal's Triangle)