杨辉三角动态规划(leetcode.118)

2020-01-03 17:46:57 浏览数 (1)

代码语言:javascript复制
class Solution {
public:
    vector<vector<int>> generate(int numRows) {
        vector<vector<int>> result(numRows);
        if(numRows == 0)
            return result;
        
        for(int i = 0;i < numRows;i  ){
            for(int j = 0;j <= i;j  ){
                if(j == 0 || j == i)
                    result[i].push_back(1);
                else
                    result[i].push_back(result[i-1][j]   result[i-1][j-1]);
            }
        }

        return result;
    }
};

0 人点赞