Skip to content

Commit 5b0692d

Browse files
authored
Merge pull request #2142 from ymir0804/main
[ymir0804] WEEK 04 solutions
2 parents 166dad2 + 08b539e commit 5b0692d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int[] productExceptSelf(int[] nums) {
3+
int [] result = new int [nums.length];
4+
result[0] = 1;
5+
for (int i = 1; i < nums.length; i++) {
6+
result[i] = result[i - 1] * nums[i - 1];
7+
}
8+
int suffixProduct = 1;
9+
for (int i = nums.length - 1; i >= 0; i--) {
10+
result[i] *= suffixProduct;
11+
suffixProduct *= nums[i];
12+
}
13+
return result;
14+
}
15+
}
16+

0 commit comments

Comments
 (0)