剑指Offer—51—构建乘积数组
来源:互联网 发布:淘宝店铺推广方法大全 编辑:程序博客网 时间:2024/06/06 18:00
构建乘积数组 : 给定一个数组 A[0,1,…,n-1],请构建一个数组B[0,1,…,n-1],其中 B 中的元素B[i]=A[0]*A[1]*…*A[i-1]*A[i+1]*…*A[n-1]。不能使用除法。
package A51构建乘积数组;import java.util.ArrayList;public class Solution { public int[] multiply(int[] A) { // 矩阵法 if (A.length == 0 || A == null){ return A; } int[] B = new int[A.length]; B[0] = 1; for (int i = 1; i < A.length; i++) { B[i] = B[i-1]*A[i-1]; } int temp = 1; for (int i = A.length-2; i >= 0 ; i--) { temp *= A[i+1]; B[i] = B[i]*temp; } return B; }}
阅读全文
0 0
- 《剑指offer》——构建乘积数组
- 《剑指offer》——构建乘积数组
- 剑指offer——构建乘积数组
- 剑指offer——构建乘积数组
- 剑指offer—构建乘积数组
- 剑指offer—构建乘积数组
- 剑指Offer—51—构建乘积数组
- 剑指offer——51.构建乘积数组
- 剑指offer——面试题52:构建乘积数组
- 剑指offer--构建乘积数组
- 《剑指offer》构建乘积数组
- 剑指offer-构建乘积数组
- 剑指offer:构建乘积数组
- 剑指offer:构建乘积数组
- 剑指offer:构建乘积数组
- [剑指offer]构建乘积数组
- 剑指offer|构建乘积数组
- 《剑指offer》-构建乘积数组
- 【关系是双人舞,两个人跳得开心才…
- Http协议
- git合并多个提交
- 【一个杀人犯的养成:无法向父母撒…
- Python实现进度条总结
- 剑指Offer—51—构建乘积数组
- 【依靠自己可以获得幸福的人生吗?…
- 【一个痛苦迷茫的年轻人的困惑】人…
- 【同步荡秋千让学前儿学会合作】说…
- JAVA设计模式(十九)----观察者模式
- 【不要拿生命來開玩笑】「老婆,你…
- 【忧鬱症、专注力不集中,和饮食也…
- 基数排序(radixSort)
- 【父母的教育角色要及早扮演】“古…