美文网首页Leetcode
Leetcode 118. Pascal's Trian

Leetcode 118. Pascal's Trian

作者: SnailTyan | 来源:发表于2018-10-18 18:49 被阅读3次

    文章作者:Tyan
    博客:noahsnail.com  |  CSDN  |  简书

    1. Description

    Pascal's Triangle

    2. Solution

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

    Reference

    1. https://leetcode.com/problems/pascals-triangle/description/

    相关文章

      网友评论

        本文标题:Leetcode 118. Pascal's Trian

        本文链接:https://www.haomeiwen.com/subject/fabszftx.html