Given numRows, generate the first numRows of Pascal’s triangle.
For example, given numRows = 5,
Return
[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
解法1: O(N^2) N 是numRows
很基础的题,注意第i层的第j个字符是第i-1层的第j个数和第j-1个数之和就可以了。
C++
Java
Given numRows, generate the first numRows of Pascal’s triangle.
For example, given numRows = 5,
Return
[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
很基础的题,注意第i层的第j个字符是第i-1层的第j个数和第j-1个数之和就可以了。
C++
Java