解题思路1:
代码:
import java.util.ArrayList;
public class Solution {
public int[] multiply(int[] A) {
int length = A.length;
int[] B1 = new int[length];
int[] B2 = new int[length];
int[] B = new int[length];
//下三角
int B1Sum = 1;
B1[0] = B1Sum;
for(int i = 1; i < length ; i++){
B1Sum*= A[i-1];
B1[i] = B1Sum;
}
//上三角
int B2Sum = 1;
B2[length - 1] = B2Sum;
for(int i = length - 1 - 1; i >= 0 ; i--){
B2Sum*=A[i + 1];
B2[i] = B2Sum;
}
//上下三角形合并
for(int i = 0 ; i < length ; i++){
B[i] = B1[i]*B2[i];
}
return B;
}
}