118. Pascal‘s Triangle (DP)

Given an integer numRows, return the first numRows of Pascal's triangle. 

we will use the top to bottom DP to do this question. First, from observation, we know that each row's first element and last element are 1.
Other elements follow a rule that dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j].
Thus, we just need to initilize the first and last element to be 1, and apply the logic above to the rest of the elements.
class Solution {
public:
vector> gener

118. Pascal‘s Triangle (DP)最先出现在Python成神之路

版权声明:
作者:cc
链接:https://www.techfm.club/p/31221.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>