Skip to content

Commit 221449c

Browse files
committed
product of array except self solution
1 parent 1a60d1d commit 221449c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

product-of-array-except-self/robinyoon-dev.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,38 @@
44
*/
55
var productExceptSelf = function (nums) {
66

7+
const prefixProductArray = new Array(nums.length);
8+
const suffixProductArray = new Array(nums.length);
9+
const totalProductArray = new Array(nums.length);
10+
11+
//prefixProductArray의 기본값 설정
12+
prefixProductArray[0] = 1;
13+
prefixProductArray[1] = nums[0];
14+
15+
//suffixProductArray의 기본값 설정
16+
suffixProductArray[nums.length - 1] = 1;
17+
suffixProductArray[nums.length - 2] = nums[nums.length - 1];
18+
19+
for (let i = 2; i < nums.length; i++) {
20+
prefixProductArray[i] = nums[i - 1] * prefixProductArray[i - 1];
21+
}
22+
23+
for (let i = nums.length - 3; i >= 0; i--) {
24+
suffixProductArray[i] = nums[i + 1] * suffixProductArray[i + 1];
25+
}
26+
27+
for (let i = 0; i < nums.length; i++) {
28+
totalProductArray[i] = prefixProductArray[i] * suffixProductArray[i];
29+
}
30+
31+
return totalProductArray;
32+
33+
};
34+
35+
//-------------1회차 풀이(6기)-------------
36+
/*
37+
var productExceptSelf = function (nums) {
38+
739
const NUMS_LENGTH = nums.length;
840
const isZeroArray = []; //boolean
941
let zeroCount = 0;
@@ -40,4 +72,7 @@ var productExceptSelf = function (nums) {
4072
4173
return tempArray;
4274
};
75+
*/
76+
77+
4378

0 commit comments

Comments
 (0)