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.
2 parents 166dad2 + 08b539e commit 5b0692dCopy full SHA for 5b0692d
product-of-array-except-self/ymir0804.java
@@ -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