We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e31138c commit 27dddb9Copy full SHA for 27dddb9
java/238-Product-of-Array-Except-Self.java
@@ -17,17 +17,13 @@ public int[] productExceptSelf(int[] nums) {
17
return arr;
18
}
19
20
- // using nums[] as the prefix calculation table
21
public int[] productExceptSelfNumsAsPrefix(int[] nums) {
22
int[] output = new int[nums.length];
23
- output[0] = 1; // default prefix is 1.
+ output[0] = 1;
24
25
- // prefix
26
for (int i = 0; i < nums.length - 1; i++)
27
output[i + 1] = output[i] * nums[i];
28
29
- // postfix
30
- // we start at nums.length - 2 because multiplying by 1 is silly.
31
for (int i = nums.length - 2; i >= 0; i--) {
32
output[i] = nums[i + 1] * output[i];
33
nums[i] = nums[i] * nums[i + 1];
0 commit comments