当前位置:网站首页>LeetCode#118. Yanghui triangle
LeetCode#118. Yanghui triangle
2022-07-06 15:21:00 【Rufeng ZHHH】
subject :
Given a nonnegative integer numRows, Generate 「 Yang hui triangle 」 Before numRows That's ok .
stay 「 Yang hui triangle 」 in , Each number is the sum of the numbers at the top left and right of it .

Example 1:
Input : numRows = 5
Output : [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
Example 2:
Input : numRows = 1
Output : [[1]]
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/pascals-triangle
The problem is not difficult , We can find out the special situation first ( When numsRows be equal to 1 or 2 The case when ), Then find out the rules and operate according to the animation demonstration .
class Solution:
def generate(self, numRows: int) -> List[List[int]]:
if numRows==1:
return [[1]]
elif numRows==2:
return [[1],[1,1]]
else:
end=[[1],[1,1]]
j=1
while j <= numRows-2:
ls=[1]
for i in range(1,j+1):
ls.append(end[j][i-1]+end[j][i])
ls.append(1)
end.append(ls)
j+=1
return end
边栏推荐
- Preface to the foundations of Hilbert geometry
- The number of reversing twice in leetcode simple question
- ucore lab 2
- How to change XML attribute - how to change XML attribute
- Emqtt distribution cluster and node bridge construction
- What are the business processes and differences of the three basic business modes of Vos: direct dial, callback and semi direct dial?
- Mysql database (III) advanced data query statement
- Crawler series of learning while tapping (3): URL de duplication strategy and Implementation
- Pedestrian re identification (Reid) - Overview
- 全网最详细的postman接口测试教程,一篇文章满足你
猜你喜欢

Scoring system based on 485 bus
What is "test paper test" in software testing requirements analysis

What are the commonly used SQL statements in software testing?
软件测试方法有哪些?带你看点不一样的东西

Winter vacation daily question - maximum number of balloons
What if software testing is too busy to study?

ucore lab1 系统软件启动过程 实验报告

Word macro operation: convert the automatic number in the document into editable text type

Daily code 300 lines learning notes day 9
![[C language] twenty two steps to understand the function stack frame (pressing the stack, passing parameters, returning, bouncing the stack)](/img/3a/aadde60352c42199ba287a6997acfa.jpg)
[C language] twenty two steps to understand the function stack frame (pressing the stack, passing parameters, returning, bouncing the stack)
随机推荐
遇到程序员不修改bug时怎么办?我教你
自动化测试中敏捷测试怎么做?
STC-B学习板蜂鸣器播放音乐2.0
Thinking about three cups of tea
软件测试Bug报告怎么写?
Global and Chinese market of RF shielding room 2022-2028: Research Report on technology, participants, trends, market size and share
Jupyter installation and use tutorial
Mysql database (I)
[HCIA continuous update] working principle of static route and default route
Which version of MySQL does php7 work best with?
Leetcode notes - dynamic planning -day6
ucore lab 2
What are the business processes and differences of the three basic business modes of Vos: direct dial, callback and semi direct dial?
Take you to use wxpy to create your own chat robot (plus wechat interface basic data visualization)
ucore lab7
ArrayList集合
Expanded polystyrene (EPS) global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
[pytorch] simple use of interpolate
软件测试面试回答技巧
MySQL数据库(二)DML数据操作语句和基本的DQL语句