首页 > 代码库 > Pascal's Triangle

Pascal's Triangle

class Solution {
public:
    vector<vector<int> > generate(int numRows) {
        vector< vector<int> > result;
        vector<int> innerResult;
        int i = 0;
        int j = 0;
        for(i = 0; i < numRows; i++){
            innerResult.clear();
            for(j = 0; j <= i; j++){
                if(j == 0 || j == i){
                    innerResult.push_back(1);
                } else {
                    innerResult.push_back(result[i-1][j-1]+result[i-1][j]);
                }
            }
            result.push_back(innerResult);
        }
        return result;
         
    }
};

Pascal's Triangle