当前位置:网站首页>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
边栏推荐
- ucore lab1 系统软件启动过程 实验报告
- Daily code 300 lines learning notes day 9
- Thinking about three cups of tea
- 遇到程序员不修改bug时怎么办?我教你
- UCORE lab1 system software startup process experimental report
- How to become a good software tester? A secret that most people don't know
- Mysql database (IV) transactions and functions
- Introduction to safety testing
- FSM和i2c实验报告
- What to do when programmers don't modify bugs? I teach you
猜你喜欢
![[HCIA continuous update] advanced features of routing](/img/05/a9ed32ec8c19b236355d48f7c2ad80.jpg)
[HCIA continuous update] advanced features of routing

UCORE lab8 file system experiment report

Servlet
What are the software testing methods? Show you something different
软件测试需求分析之什么是“试纸测试”

The number of reversing twice in leetcode simple question

Report on the double computer experiment of scoring system based on 485 bus

The minimum sum of the last four digits of the split digit of leetcode simple problem

FSM和i2c实验报告
软件测试面试要问的性能测试术语你知道吗?
随机推荐
Want to change jobs? Do you know the seven skills you need to master in the interview software test
Your wechat nickname may be betraying you
Global and Chinese markets of PIM analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
Install and run tensorflow object detection API video object recognition system of Google open source
Lab 8 文件系统
STC-B学习板蜂鸣器播放音乐
Sleep quality today 81 points
[pytorch] simple use of interpolate
Pedestrian re identification (Reid) - Overview
JDBC介绍
安全测试入门介绍
软件测试面试回答技巧
软件测试需求分析之什么是“试纸测试”
Rearrange spaces between words in leetcode simple questions
MySQL development - advanced query - take a good look at how it suits you
Programmers, how to avoid invalid meetings?
CSAPP shell lab experiment report
基于485总线的评分系统双机实验报告
CSAPP家庭作業答案7 8 9章
Global and Chinese markets for complex programmable logic devices 2022-2028: Research Report on technology, participants, trends, market size and share