找工作找工作,放弃秋招了,加油春招吧。
自己的思路
无思路,不用除法,感觉好怪,只能用前缀乘积了,记录两个。
class Solution {
public int[] productExceptSelf(int[] nums) {
//不要使用除法?
int len = nums.length;
int[] presum = new int[len], nextsum = new int[len], ans = new int[len];
presum[0] = nums[0];
nextsum[len-1] = nums[len-1];
for(int i = 1; i < len; i++){
presum[i] = presum[i-1] * nums[i] ;
}
for(int i = len - 2; i >= 0; i--){
nextsum[i] = nextsum[i+1] * nums[i] ;
}
ans[0] = nextsum[1];
ans[len-1] = presum[len-2];
for(int i = 1; i < len - 1; i++){
ans[i] = presum[i-1] * nextsum[i+1];
}
return ans;
}
}