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 0f4baad commit efd1621Copy full SHA for efd1621
product-of-array-except-self/iam-edwin.java
@@ -0,0 +1,19 @@
1
+class Solution {
2
+ public int[] productExceptSelf(int[] nums) {
3
+ int[] left = new int[nums.length + 1];
4
+ int[] right = new int[nums.length + 1];
5
+ left[0] = 1;
6
+ right[nums.length] = 1;
7
+
8
+ for (int i = 0; i < nums.length; i++) {
9
+ left[i + 1] = left[i] * nums[i];
10
+ right[nums.length - i - 1] = right[nums.length - i] * nums[nums.length - i - 1];
11
+ }
12
13
+ int[] result = new int[nums.length];
14
15
+ result[i] = left[i] * right[i + 1];
16
17
+ return result;
18
19
+}
0 commit comments