题目:
思路:
https://zhuanlan.zhihu.com/p/109306706?utm_id=0
代码:
java
int n = nums.length;
int[] l = new int[nums.length];
int[] r = new int[nums.length];
l[0] = 1;
r[n-1] = 1;
for (int i=1;i<nums.length;i++) {
l[i] = l[i-1] * nums[i-1];
}
for (int j=nums.length -2;j>=0;j--) {
r[j] = r[j+1] * nums[j+1];
}
int[] answer = new int[nums.length];
for (int i=0;i<n;i++) {
answer[i] = l[i] * r[i];
}
return answer;