Leetcode 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;
         
    }
};

posted @ 2015-02-04 13:29  mfrbuaa  阅读(123)  评论(0编辑  收藏  举报