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 10a9497 commit 744b5acCopy full SHA for 744b5ac
product-of-array-except-self/ymir0804.java
@@ -0,0 +1,15 @@
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
+}
0 commit comments