```
public int[] productExceptSelf(int[] nums) {
int res[] = new int[nums.length], left = 1, right = 1;
for (int i = 0; i < res.length; left *= nums[i++])
res[i] = left;
for (int i = res.length - 1; i >= 0; right *= nums[i--])
res[i] *= right;
return res;
}
```