当前位置:网站首页>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 simple question: check whether two strings are almost equal
- Crawler series of learning while tapping (3): URL de duplication strategy and Implementation
- Global and Chinese market of maleic acid modified rosin esters 2022-2028: Research Report on technology, participants, trends, market size and share
- Which version of MySQL does php7 work best with?
- The most detailed postman interface test tutorial in the whole network. An article meets your needs
- 软件测试方法有哪些?带你看点不一样的东西
- Global and Chinese markets for complex programmable logic devices 2022-2028: Research Report on technology, participants, trends, market size and share
- Servlet
- Daily code 300 lines learning notes day 9
- The latest query tracks the express logistics and analyzes the method of delivery timeliness
猜你喜欢
[C language] twenty two steps to understand the function stack frame (pressing the stack, passing parameters, returning, bouncing the stack)
51 lines of code, self-made TX to MySQL software!
Threads et pools de threads
Rearrange spaces between words in leetcode simple questions
How to rename multiple folders and add unified new content to folder names
China's county life record: go upstairs to the Internet, go downstairs' code the Great Wall '
Scoring system based on 485 bus
软件测试行业的未来趋势及规划
Introduction to safety testing
想跳槽?面试软件测试需要掌握的7个技能你知道吗
随机推荐
MySQL transactions
A method and implementation of using VSTO to prohibit excel cell editing
Stc-b learning board buzzer plays music
遇到程序员不修改bug时怎么办?我教你
软件测试方法有哪些?带你看点不一样的东西
Maximum nesting depth of parentheses in leetcode simple questions
Investment should be calm
Global and Chinese markets for GaN on diamond semiconductor substrates 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
[HCIA continuous update] advanced features of routing
Global and Chinese market of maleic acid modified rosin esters 2022-2028: Research Report on technology, participants, trends, market size and share
UCORE lab2 physical memory management experiment report
软件测试需求分析之什么是“试纸测试”
Investment operation steps
STC-B学习板蜂鸣器播放音乐2.0
ucore lab5用户进程管理 实验报告
Introduction to safety testing
ucorelab4
Programmers, how to avoid invalid meetings?
[pytorch] simple use of interpolate