解法特殊,建议记忆
class Solution {
public int[] productExceptSelf(int[] nums) {
int length = nums.length;
int[] forward = new int[length];
int[] back = new int[length];
forward[0] = 1;
back[length - 1] = 1;
for (int i = 1; i < length; i++) {
forward[i] = forward[i - 1] * nums[i - 1];
}
for (int i = length - 2; i >= 0; i--) {
back[i] = back[i + 1] * nums[i + 1];
}
for (int i = 0; i < length; i++) {
forward[i] = forward[i] * back[i];
}
return forward;
}
}