您的位置:首页 > 其它

238 Product of Array Except Self

2015-07-20 15:37 274 查看
网上的

public class Solution {
public int[] productExceptSelf(int[] nums) {
int[] res = new int[nums.length];
res[res.length-1] = 1;
for(int i=nums.length-2; i>=0; i--) {
res[i] = res[i+1] * nums[i+1];
}

int left = 1;
for(int i=0; i<nums.length; i++) {
res[i] *= left;
left *= nums[i];
}
return res;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: