当前位置:网站首页>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
边栏推荐
- Leetcode notes - dynamic planning -day7
- UCORE lab1 system software startup process experimental report
- Brief description of compiler optimization level
- How to do agile testing in automated testing?
- Capitalize the title of leetcode simple question
- Intensive learning notes: Sutton book Chapter III exercise explanation (ex17~ex29)
- Threads and thread pools
- Emqtt distribution cluster and node bridge construction
- CSAPP家庭作業答案7 8 9章
- What if software testing is too busy to study?
猜你喜欢
Report on the double computer experiment of scoring system based on 485 bus
Servlet
Portapack application development tutorial (XVII) nRF24L01 launch B
The wechat red envelope cover designed by the object is free! 16888
How to write the bug report of software test?
Leetcode notes - dynamic planning -day7
CSAPP家庭作业答案7 8 9章
Take you to use wxpy to create your own chat robot (plus wechat interface basic data visualization)
CSAPP homework answers chapter 789
MySQL数据库(四)事务和函数
随机推荐
UCORE lab5 user process management experiment report
Opencv recognition of face in image
The latest query tracks the express logistics and analyzes the method of delivery timeliness
MySQL数据库(三)高级数据查询语句
UCORE lab1 system software startup process experimental report
[200 opencv routines] 98 Statistical sorting filter
Build your own application based on Google's open source tensorflow object detection API video object recognition system (II)
Jupyter installation and use tutorial
C4D quick start tutorial - creating models
软件测试面试要问的性能测试术语你知道吗?
Global and Chinese market for antiviral coatings 2022-2028: Research Report on technology, participants, trends, market size and share
Daily code 300 lines learning notes day 9
How to build a nail robot that can automatically reply
STC-B学习板蜂鸣器播放音乐2.0
Global and Chinese markets of PIM analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
The maximum number of words in the sentence of leetcode simple question
csapp shell lab
Leetcode notes - dynamic planning -day6
Intensive learning notes: Sutton book Chapter III exercise explanation (ex17~ex29)
Introduction to safety testing