Skip to content

Commit

Permalink
Remove explanation from comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad-A0 authored Aug 29, 2022
1 parent e31138c commit 27dddb9
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions java/238-Product-of-Array-Except-Self.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@ public int[] productExceptSelf(int[] nums) {
return arr;
}

// using nums[] as the prefix calculation table
public int[] productExceptSelfNumsAsPrefix(int[] nums) {
int[] output = new int[nums.length];
output[0] = 1; // default prefix is 1.
output[0] = 1;

// prefix
for (int i = 0; i < nums.length - 1; i++)
output[i + 1] = output[i] * nums[i];

// postfix
// we start at nums.length - 2 because multiplying by 1 is silly.
for (int i = nums.length - 2; i >= 0; i--) {
output[i] = nums[i + 1] * output[i];
nums[i] = nums[i] * nums[i + 1];
Expand Down

0 comments on commit 27dddb9

Please sign in to comment.