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 0169498 commit 69eed8dCopy full SHA for 69eed8d
238-product-of-array-except-self/238-product-of-array-except-self.java
@@ -0,0 +1,29 @@
1
+class Solution {
2
+ public int[] productExceptSelf(int[] nums) {
3
+
4
+ int length = nums.length;
5
6
+ //Left array
7
+ int[] L = new int[length];
8
+ // right array
9
+ int[] R = new int[length];
10
11
+ int[] ans = new int[length];
12
13
+ L[0] = 1;
14
+ for(int i=1; i< length; i++){
15
+ L[i] = nums[i-1] * L[i-1];
16
+ }
17
18
+ R[length - 1] = 1;
19
+ for(int i=length-2; i >= 0; i--){
20
+ R[i] = nums[i+1] * R[i+1];
21
22
23
+ for(int i=0; i< length; i++){
24
+ ans[i] = L[i]*R[i];
25
26
27
+ return ans;
28
29
+}
0 commit comments