当前位置:网站首页>119. Pascal‘s Triangle II. Sol
119. Pascal‘s Triangle II. Sol
2022-07-05 22:17:00 【isee_ nh】
Easy Difficult questions , It's actually binomial expansion , You don't need recursion
Given an integer rowIndex
, return the rowIndexth
(0-indexed) row of the Pascal's triangle.
In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:
Example 1:
Input: rowIndex = 3 Output: [1,3,3,1]
Example 2:
Input: rowIndex = 0 Output: [1]
Example 3:
Input: rowIndex = 1 Output: [1,1]
Constraints:
0 <= rowIndex <= 33
class Solution: def fraction(self, n): product = 1 if n==0: return 1 else: for i in range(n): product = product*(i+1) return product def Pr(self, n, m): return self.fraction(n)/(self.fraction(m)*self.fraction(n-m)) def getRow(self, rowIndex): output = [] for i in range(rowIndex+1): output.append(int(self.Pr(rowIndex,i))) return output
边栏推荐
- Some tutorials install the database on ubantu so as not to occupy computer memory?
- 微服務鏈路風險分析
- Character conversion PTA
- Cobaltstrike builds an intranet tunnel
- MySQL actual combat 45 lecture learning (I)
- Comment développer un plug - in d'applet
- 多家呼吸机巨头产品近期被一级召回 呼吸机市场仍在增量竞争
- Understand the basic concept of datastore in Android kotlin and why SharedPreferences should be stopped in Android
- AD637 usage notes
- Bitbucket installation configuration
猜你喜欢
Unique occurrence times of leetcode simple questions
Wonderful review of the digital Expo | highlight scientific research strength, and Zhongchuang computing power won the digital influence enterprise award
Overview of concurrency control
CA certificate trampled pit
笔记本电脑蓝牙怎么用来连接耳机
PyGame practical project: write Snake games with 300 lines of code
装饰器学习01
A number of ventilator giants' products have been recalled recently, and the ventilator market is still in incremental competition
A trip to Suzhou during the Dragon Boat Festival holiday
2022-07-05:给定一个数组,想随时查询任何范围上的最大值。 如果只是根据初始数组建立、并且以后没有修改, 那么RMQ方法比线段树方法好实现,时间复杂度O(N*logN),额外空间复杂度O(N*
随机推荐
Analyse des risques liés aux liaisons de microservices
The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!
2022-07-05: given an array, you want to query the maximum value in any range at any time. If it is only established according to the initial array and has not been modified in the future, the RMQ meth
Search: Future Vision (moving sword)
Learning of mall permission module
Oracle views the data size of a table
What changes has Web3 brought to the Internet?
A number of ventilator giants' products have been recalled recently, and the ventilator market is still in incremental competition
Database recovery strategy
Recovery technology with checkpoints
Technology cloud report: how many hurdles does the computing power network need to cross?
C language knowledge points link
Draw a red lantern with MATLAB
每日刷题记录 (十四)
Common interview questions of redis factory
Code bug correction, char is converted to int high-order symbol extension, resulting in changes in positivity and negativity and values. Int num = (int) (unsigned int) a, which will occur in older com
database mirroring
Practice: fabric user certificate revocation operation process
The American Championship is about to start. Are you ready?
HDU 4391 paint the wall segment tree (water