【数组14】构建乘积数组
来源:互联网 发布:oracle导入txt数据 编辑:程序博客网 时间:2024/06/03 11:17
题目描述
给定一个数组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]。不能使用除法
import java.util.ArrayList;public class Solution { public int[] multiply(int[] A) { if(A==null ||A.length<=0) return A; int n=A.length; int[] front=new int[n]; int[] back=new int[n]; front[0]=1; back[n-1]=1; for(int i=1;i<n;i++){ front[i]=front[i-1]*A[i-1]; back[n-1-i]=back[n-i]*A[n-i]; } for(int i=0;i<n;i++){ front[i]*=back[i]; } return front; }}
0 0
- 【数组14】构建乘积数组
- 数组------构建乘积数组
- 数组:构建乘积数组
- 构建乘积数组
- 构建乘积数组
- 52 - 构建乘积数组
- 构建乘积数组
- 构建乘积数组
- 构建乘积数组
- 牛客网 | 构建乘积数组
- 构建乘积数组
- 【模模糊糊】构建乘积数组
- 构建乘积数组
- 构建乘积数组
- 构建乘积数组
- 构建乘积数组
- 构建乘积数组
- 构建乘积数组
- 深入解析淘宝Diamond之客户端架构
- 图片边框
- final修饰符
- 树莓派 Learning 002 装机后的必要操作 --- 06 共用键鼠 之 windows和树莓派
- String的==和equals()
- 【数组14】构建乘积数组
- HDU-5326 Work
- Leetcode 106. Construct Binary Tree from Inorder and Postorder Traversal (Medium) (cpp)
- 靠谱无脑的搞一个vpn
- 【二分图匹配】Hopcroft-Karp算法模板
- z-index详解
- HDOJ 3790 最短路径问题
- HDU Problem 1325 Is It A Tree?【并查集】
- spark编译失败 PermGen space