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 dd3d408 commit 6696959Copy full SHA for 6696959
0238_Productofarray_except_self.java
@@ -0,0 +1,32 @@
1
+class Solution {
2
+ public int[] productExceptSelf(int[] nums) {
3
+ int[] prefix = new int[nums.length];
4
+ int[] suffix =new int[nums.length];
5
+
6
7
+ prefix[0]=1;
8
+ for(int i = 1 ; i<nums.length ; i++){
9
+ prefix[i]= prefix[i-1] * nums[i-1];
10
11
+ }
12
13
14
+ suffix[suffix.length-1]=1;
15
16
+ for(int i= nums.length - 2 ; i>=0 ; i--){
17
+ suffix[i]=suffix[i+1] * nums[i+1];
18
19
20
21
22
+ int[] ans = new int[nums.length];
23
+ for(int i = 0 ; i<nums.length ; i++){
24
+ ans[i]=prefix[i]* suffix[i];
25
26
27
28
29
+ return ans;
30
31
32
+}
0 commit comments