Leetcode 118. Pascal's Triangle

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

1. Description

Pascal's Triangle

2. Solution

class Solution {
public:
    vector> generate(int numRows) {
        vector> result;
        for(int i = 0; i < numRows; i++) {
            vector 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 Triangle)