[leetcode刷题系列]Pascal's Triangle

没啥好说的哈

const int MAXN = 100 + 10;
int comb[MAXN][MAXN];
class Solution {
    int get_comb(int n, int m){
        if(m > n)
            return 0;
        if(m == 0 || n == m)
            return 1;
        int& ret = comb[n][m];
        if(ret != -1)
            return ret;
        return ret = get_comb(n - 1, m) + get_comb(n - 1, m - 1);
    }
public:
    Solution(){
        memset(comb, 0xff, sizeof(comb));
    }
    vector<vector<int> > generate(int numRows) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        vector<vector<int> > vv;
        for(int i = 0; i < numRows; ++ i){
            vector<int> vc;
            for(int j = 0; j <= i; ++ j)
                vc.push_back(get_comb(i, j));
            vv.push_back(vc);
        }
        return vv;
    }
};


你可能感兴趣的:([leetcode刷题系列]Pascal's Triangle)