当前位置:网站首页>剑指 Offer 66. 构建乘积数组
剑指 Offer 66. 构建乘积数组
2022-08-08 13:31:00 【愈努力俞幸运】
剑指 Offer 66. 构建乘积数组https://leetcode.cn/problems/gou-jian-cheng-ji-shu-zu-lcof/
狗的地方就是不让用除法
如果写成下面图片的格式
那么怎么计算b[i]呢?
可以从上往下,累乘计算下三角,
在从下网上累乘计算上三角。
class Solution:
def constructArr(self, a):
b,tmp=[1]*len(a),1
for i in range(1,len(a)-1)
b[i]=b[i-1]*a[i-1]
for i in range(len(a)-2,-1,-1):
tmp*=a[i+1]
b[i]*=tmp
return b
边栏推荐
- R语言数据类型转换:基本数据类型的转换、将一种数据类型转化为另外一种数据类型
- 数据解析(XPath、BeautifulSoup、正则表达式、pyquery)
- Knowledge points and written test questions related to shift operations, bit operations, and logical operations
- (8)FlinkSQL自定义UDF
- C语言小项目 -- 通讯录(静态版+动态版+文件版)
- AfterEffect插件-图层排序-js脚本开发-AE插件
- Pretraining Weekly Issue 56: Long Text Understanding, Instant Question Answering, Mask Self-Supervision
- (6)FlinkSQL将kafka数据写入到mysql方式一
- 医药行业转型发展,探索数字化供应链升级之道
- 使用.NET简单实现一个Redis的高性能克隆版(三)
猜你喜欢
随机推荐
Implement a customized pin code input control
【C语言】深度剖析数据在内存中的存储
哈佛大学砸场子:DALL-E 2只是「粘合怪」,生成正确率只有22%
服务器配置——Linux系统安装Redis
The use of qsort function and its analog implementation
PC端实用软件推荐
简析LDO静态电流与功耗的关系
腾讯,投了个 “离诺贝尔奖最近的华人”
Program Environment and Preprocessing
Qt的简易日志库实现及封装
[Redis] Redis installation and use of client redis-cli (batch operation)
基于Nodejs的医生预约平台的设计和实现
【低代码】1405- 浅谈低代码平台远程组件加载方案
Tsinghua | GLM-130B: An Open Bilingual Pre-training Model
Background, History and Lessons of Transfer Learning
Review: What is the pre-approval of autumn recruitment?What is an ordinary autumn move?It's all recruitment, why do you need to set these two recruitment time periods?
Jenkins - Introduction to Continuous Integration (1)
(8)FlinkSQL自定义UDF
C language small project -- address book (static version + dynamic version + file version)
医药行业转型发展,探索数字化供应链升级之道