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 7cd49d8 commit 321cd6dCopy full SHA for 321cd6d
product-of-array-except-self/Kyojin-Hwang.js
@@ -0,0 +1,24 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @return {number[]}
4
+ */
5
+var productExceptSelf = function (nums) {
6
+ const n = nums.length;
7
+ const answer = new Array(n).fill(1);
8
+
9
+ // 왼쪽 곱 계산
10
+ let prefix = 1;
11
+ for (let i = 0; i < n; i++) {
12
+ answer[i] = prefix;
13
+ prefix *= nums[i];
14
+ }
15
16
+ // 오른쪽 곱 계산
17
+ let suffix = 1;
18
+ for (let i = n - 1; i >= 0; i--) {
19
+ answer[i] *= suffix;
20
+ suffix *= nums[i];
21
22
23
+ return answer;
24
+};
0 commit comments