当前位置:网站首页>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
边栏推荐
- Investment should be calm
- 如何成为一个好的软件测试员?绝大多数人都不知道的秘密
- UCORE lab7 synchronous mutual exclusion experiment report
- Contest3145 - the 37th game of 2021 freshman individual training match_ A: Prizes
- What are the commonly used SQL statements in software testing?
- ucore Lab 1 系统软件启动过程
- China's county life record: go upstairs to the Internet, go downstairs' code the Great Wall '
- Leetcode notes - dynamic planning -day6
- Introduction to safety testing
- Servlet
猜你喜欢
Servlet
基于485总线的评分系统
Réponses aux devoirs du csapp 7 8 9
Maximum nesting depth of parentheses in leetcode simple questions
转行软件测试必需要知道的知识
C4D quick start tutorial - creating models
MySQL development - advanced query - take a good look at how it suits you
Jupyter installation and use tutorial
Threads et pools de threads
软件测试面试回答技巧
随机推荐
自动化测试你必须要弄懂的问题,精品总结
Daily code 300 lines learning notes day 9
Report on the double computer experiment of scoring system based on 485 bus
What to do when programmers don't modify bugs? I teach you
The minimum number of operations to convert strings in leetcode simple problem
Investment should be calm
The minimum sum of the last four digits of the split digit of leetcode simple problem
How to rename multiple folders and add unified new content to folder names
Mysql的事务
Brief description of compiler optimization level
转行软件测试必需要知道的知识
Practical cases, hand-in-hand teaching you to build e-commerce user portraits | with code
The number of reversing twice in leetcode simple question
What are the commonly used SQL statements in software testing?
如何成为一个好的软件测试员?绝大多数人都不知道的秘密
CSAPP家庭作业答案7 8 9章
Scoring system based on 485 bus
Rearrange spaces between words in leetcode simple questions
The latest query tracks the express logistics and analyzes the method of delivery timeliness
Nest and merge new videos, and preset new video titles