题解 | #构建乘积数组#动态规划
构建乘积数组
http://www.nowcoder.com/practice/94a4d381a68b47b7a8bed86f2975db46
public int[] multiply(int[] A) {
int n = A.length;
int[] B = new int[n];
// 从左到右累乘
for (int i = 0,product = 1; i < n;product *= A[i], i++) {
B[i] = product;
}
// 从右往左累乘
for (int i = n - 1,product = 1; i >= 0;product *= A[i], i--) {
B[i] *= product;
}
return B;
}