1. 题目描述
2. coding
import java.util.ArrayList;
public class Solution {
public int[] multiply(int[] A) {
int len = A.length;
if (len == 0) {
return null;
}
int[] B = new int[len];
B[0] = 1;
for(int i = 1; i < len; i++) {
B[i] = B[i - 1] * A[i - 1];
}
int temp = 1;
for(int i = len - 1; i >= 0; i--){
B[i] *= temp;
temp *= A[i];
}
return B;
}
}
import java.util.ArrayList;
public class Solution {
public int[] multiply(int[] A) {
int len = A.length;
if (len == 0) {
return null;
}
int[] B = new int[len];
int[] l = new int[len];
int[] r = new int[len];
l[0] = A[0];
r[len - 1] = A[len - 1];
for (int i = 1; i < len; i ++) {
l[i] = l[i - 1] * A[i];
r[len - i - 1] = r[len - i] * A[len - i - 1];
}
B[0] = r[0];
for (int i = 1; i < len - 1; i ++) {
B[i] = l[i - 1] * r[i + 1];
}
B[len - 1] = l[len - 2];
return B;
}
}