File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
product-of-array-except-self Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 44 */
55var 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
You can’t perform that action at this time.
0 commit comments