题解 | #构建乘积数组#
构建乘积数组
http://www.nowcoder.com/practice/94a4d381a68b47b7a8bed86f2975db46
public class Solution {
public int[] multiply(int[] A) {
if(A.length == 0 || A.length == 1){
return null;
}
int l = A.length;
int[] B = new int[l];
B[0] = 1;
for(int i = 1;i < l;i ++){
B[i] = B[i-1] * A[i-1];
}
int temp = 1;
for(int i = l-2;i >=0;i --){
temp = temp * A[i+1];
B[i] = B[i] * temp;
}
return B;
}
}