当前位置:网站首页>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
边栏推荐
- 想跳槽?面试软件测试需要掌握的7个技能你知道吗
- Winter vacation daily question - maximum number of balloons
- Dlib detects blink times based on video stream
- Leetcode simple question: check whether the numbers in the sentence are increasing
- Servlet
- Introduction to variable parameters
- ucore lab2 物理内存管理 实验报告
- Daily code 300 lines learning notes day 9
- Pedestrian re identification (Reid) - data set description market-1501
- 几款开源自动化测试框架优缺点对比你知道吗?
猜你喜欢

STC-B学习板蜂鸣器播放音乐2.0
Interview answering skills for software testing

ucore lab5用户进程管理 实验报告
软件测试行业的未来趋势及规划

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

線程及線程池

软件测试Bug报告怎么写?

C4D quick start tutorial - creating models
What is "test paper test" in software testing requirements analysis

ucore lab5
随机推荐
Dlib detects blink times based on video stream
Global and Chinese market of maleic acid modified rosin esters 2022-2028: Research Report on technology, participants, trends, market size and share
ArrayList集合
Leetcode notes - dynamic planning -day6
UCORE LaB6 scheduler experiment report
Mysql database (II) DML data operation statements and basic DQL statements
UCORE lab5 user process management experiment report
Eigen User Guide (Introduction)
How to write the bug report of software test?
Future trend and planning of software testing industry
Do you know the performance testing terms to be asked in the software testing interview?
Mysql database (IV) transactions and functions
Heap, stack, queue
MySQL数据库(三)高级数据查询语句
Brief introduction to libevent
Scoring system based on 485 bus
Crawler series of learning while tapping (3): URL de duplication strategy and Implementation
Mysql database (I)
[pytorch] simple use of interpolate
UCORE lab8 file system experiment report