当前位置:网站首页>剑指 Offer 66. 构建乘积数组
剑指 Offer 66. 构建乘积数组
2022-06-29 19:37:00 【Yake1965】
剑指 Offer 66. 构建乘积数组
class Solution {
public int[] constructArr(int[] a) {
int n = a.length;
if(n == 0) return new int[0];
int[] ans = new int[n]; // ans[i] 表示索引 i 左侧所有元素的乘积
ans[0] = 1; // 因为索引为 '0' 的元素左侧没有元素,所以 ans[0] = 1
for(int i = 1; i < n; i ++)
ans[i] = a[i-1] * ans[i-1];
// R 为右侧所有元素的乘积,刚开始右边没有元素,所以 R = 1
for(int i = n - 1, r = 1; i >= 0; i--){
ans[i] = ans[i] * r; // 对于索引 i,左边的乘积为 ans[i],右边的乘积为 R
r *= a[i];
}
return ans;
}
}
边栏推荐
- 4-1端口扫描技术
- JVM(3) 类加载
- Flutter 2.0 FocusScope. of(context). The requestfocus (focusnode()) does not take effect
- 建立自己的网站(12)
- Nacos problem
- Wechat launched the picture big bang function; Apple's self-developed 5g chip may have failed; Microsoft solves the bug that causes edge to stop responding | geek headlines
- How to install and use computer SSD hard disk
- Kdd 2022 | prise en compte de l'alignement et de l'uniformité des représentations dans le Filtrage collaboratif
- 正则表达式系列之手机号码正则
- 3-2主机发现-三层发现
猜你喜欢

QC protocol + Huawei fcp+ Samsung AFC fast charging 5v9v chip fs2601 application

Violent solution to the question of guessing the ranking

【️爬虫必备->Scrapy框架从黑铁到王者️】初篇——万字博文详解(建议收藏)

Wechat launched the picture big bang function; Apple's self-developed 5g chip may have failed; Microsoft solves the bug that causes edge to stop responding | geek headlines

MySQL remote connection

KDD 2022 | 协同过滤中考虑表征对齐和均匀性

开发者任务中心上线!千元豪礼送不停!

Kdd 2022 | prise en compte de l'alignement et de l'uniformité des représentations dans le Filtrage collaboratif
![[software testing] 01 -- software life cycle and software development model](/img/57/a4fcb40a33c80b0bcf2187d1943abd.jpg)
[software testing] 01 -- software life cycle and software development model

Win11系统小组件打不开?Win11系统小组件无法打开解决方法
随机推荐
开发者任务中心上线!千元豪礼送不停!
以其他组件为代价的性能提升不是好提升
QC协议+华为FCP+三星AFC快充取电5V9V芯片FS2601应用
【U盘检测】为了转移压箱底的资料,买了个2T U盘检测仅仅只有47G~
细说GaussDB(DWS)复杂多样的资源负载管理手段
QC protocol + Huawei fcp+ Samsung AFC fast charging 5v9v chip fs2601 application
JVM(4) 字节码技术+运行期优化
【剑指Offer】51. 数组中的逆序对
JVM (2) garbage collection
学习放大器至少要3年?
Physical verification LVS process and Technology (Part I)
Escape and March, the "two-sided Jianghu" of temporary food
领先11%,华为云天筹AI求解器再度登顶国际权威榜单
Lingyun going to sea | Wenhua online &huawei cloud: creating a new solution for smart teaching in Africa
JVM (4) Bytecode Technology + Runtime Optimization
The concept and properties of mba-day26 number
Static static member variables use @value injection
福昕软件受邀亮相2022先进制造业数智发展论坛
微信推出图片大爆炸功能;苹果自研 5G 芯片或已失败;微软解决导致 Edge 停止响应的 bug|极客头条
mysql远程连接