We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 11bf512 commit cfd8940Copy full SHA for cfd8940
Arrays/productOfArrayExceptSelf.js
@@ -0,0 +1,39 @@
1
+
2
+var productExceptSelf = function(nums) {
3
4
+ const prefixArray=[];
5
6
+ const suffixArray=[];
7
8
+ let prefixProduct=1;
9
+ let suffixProduct=1;
10
11
+ for(let ind=0;ind<nums.length;ind++){
12
13
+ if(ind==0){
14
+ prefixArray[0]=prefixProduct;
15
+ }
16
+ else{
17
+ prefixProduct*=nums[ind-1];
18
+ prefixArray[ind]=prefixProduct;
19
20
21
+ for(let ind=nums.length-1;ind>=0;ind--){
22
23
+ if(ind==nums.length-1){
24
+ suffixArray[ind]=1;
25
26
27
+ suffixProduct*=nums[ind+1];
28
+ suffixArray[ind]=suffixProduct;
29
30
31
+ let result=[];
32
33
+ for(let j=0;j<prefixArray.length;j++){
34
35
+ result[j]=(prefixArray[j]*suffixArray[j]);
36
37
38
+ return result;
39
+};
0 commit comments