Skip to content

Commit 69eed8d

Browse files
committed
Time: 1 ms (100.00%), Space: 50.9 MB (82.27%) - LeetHub
1 parent 0169498 commit 69eed8d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)