Skip to content

Commit fa2826c

Browse files
committed
product-of-array-except-self풀이
1 parent d45338c commit fa2826c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

product-of-array-except-self/youngduck.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ var productExceptSelf = function (nums) {
77

88
const result = new Array(numsLength).fill(1);
99

10+
// for문 하나로 처리할경우 O(n^2).
11+
// for문 두개로 나눠서 처리할경우 O(n). 누적곱 개념을 활용해줘야함
12+
1013
let left = 1;
1114
let right = 1;
1215

@@ -18,9 +21,7 @@ var productExceptSelf = function (nums) {
1821
right *= nums[numsLength - i - 1];
1922
}
2023

21-
// TC: O(n), SC: O(1)
24+
// 시간복잡도: O(n), 공간복잡도: O(1)
2225

2326
return result;
2427
};
25-
26-
console.log(productExceptSelf([1, 2, 3, 4]));

0 commit comments

Comments
 (0)