public static int[] multiply(int[] A) {
//A[i]的前缀乘积表达式 mul_pre[i] = A[0]*A[1]*A[2]*A[3]....A[i-1];
// A[i]的后缀乘积表达式 mul_post[i] = A[i+1]*A[i+2]*A[i+3]*....A[n-1];
//B[i] = mul_pre[i] * mul_post[i]
int[] B = new int[A.length];
//计算B数组值
for (int i = 0; i < B.length; i++) {
B[i] = pre_mul(i,A)*post_mul(i,A);
}
return B;
}
//1 前缀乘积表达式:A[i]的前缀乘积表达式 res: A[i] = A[0]*A[1]*A[2]*A[3]....A[i-1];
public static int pre_mul(int j,int[] A){
int[] resPre = new int[A.length];
//1、如果j=0的情况,前缀乘积就指定为1
int res_pre = 1;
if (j==0) {
res_pre = 1;
resPre[j] = res_pre; //存储在结果数组中
//2、如果j!=0的i情况,都可以进行计算累乘
}else{
for (int i = 0; i <= j-1; i++) {
res_pre *= A[i];
}
//累乘之后,把结果存储进去到相应的j的位置
resPre[j] = res_pre; //存储到结果数组中
}
//返回本次调用的结果值
return resPre[j];
}
//2 后缀乘积表达式:A[i]的前缀乘积表达式 res: A[i] = A[i+1]*A[i+2]*A[i+3]*....A[n-1];
public static int post_mul(int j,int[] A){
int[] resPost = new int[A.length];
//1、如果j=0的情况,前缀乘积就指定为1
int res_pre = 1;
if (j==A.length-1) {
res_pre = 1;
resPost[j] = res_pre; //存储在结果数组中
//2、如果j!=A.length-1的情况,都可以进行计算累乘
}else{
for (int i = A.length-1; i >= j+1; i--) {
res_pre *= A[i];
}
//累乘之后,把结果存储进去到相应的j的位置
resPost[j] = res_pre; //存储到结果数组中
}
//返回本次调用的结果值
return resPost[j];
}