Q118. Pascal's Triangle

直达:https://leetcode.com/problems/pascals-triangle/description/

GivennumRows, generate the firstnumRowsof Pascal's triangle.

For example, givennumRows= 5, Return

[
     [1],
    [1,1],
   [1,2,1],
  [1,3,3,1],
 [1,4,6,4,1]
]

分析

帕斯卡三角的特征是

从1开始,以下第i行的第j个元素满足:

  1. 如果 j==0 || i == j, pas[i][j] = 1;

  2. 否则 pas[i][j] = pas[i-1][j-1] + pas[i][j]

C++代码

Last updated

Was this helpful?