当前位置:网站首页>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 <= 33class 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
边栏推荐
猜你喜欢

Sentinel production environment practice (I)

科技云报道荣膺全球云计算大会“云鼎奖”2013-2022十周年特别贡献奖

AD637 usage notes

Calculation method of boundary IOU

科技云报道:算力网络,还需跨越几道坎?

MySQL disconnection reports an error MySQL ldb_ exceptions. OperationalError 4031, The client was disconnected by the server

Blocking protocol for concurrency control

【愚公系列】2022年7月 Go教学课程 004-Go代码注释

Business learning of mall commodity module

Storage optimization of performance tuning methodology
随机推荐
Practice: fabric user certificate revocation operation process
Interprocess communication in the "Chris Richardson microservice series" microservice architecture
Depth first DFS and breadth first BFS -- traversing adjacency tables
Sub total of Pico development
Multiplexing of Oracle control files
Text组件新增内容通过tag_config设置前景色、背景色
Common interview questions of redis factory
Tips for using SecureCRT
Poj3414 extensive search
Oracle hint understanding
Leetcode simple question: check whether each row and column contain all integers
Leetcode simple question check whether all characters appear the same number of times
CRM creates its own custom report based on fetch
Business learning of mall order module
The statistics of leetcode simple question is the public string that has appeared once
K210 learning notes (IV) k210 runs multiple models at the same time
Serializability of concurrent scheduling
2022-07-05:给定一个数组,想随时查询任何范围上的最大值。 如果只是根据初始数组建立、并且以后没有修改, 那么RMQ方法比线段树方法好实现,时间复杂度O(N*logN),额外空间复杂度O(N*
MySQL actual combat 45 lecture learning (I)
Win11 runs CMD to prompt the solution of "the requested operation needs to be promoted"