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 1636c6f commit deefbd6Copy full SHA for deefbd6
product-of-array-except-self/hyer0705.ts
@@ -0,0 +1,16 @@
1
+function productExceptSelf(nums: number[]): number[] {
2
+ const n = nums.length;
3
+ const result = Array(n).fill(1);
4
+
5
+ for (let i = 1; i < n; i++) {
6
+ result[i] = nums[i - 1] * result[i - 1];
7
+ }
8
9
+ let suffixProduct = 1;
10
+ for (let i = n - 1; i >= 0; i--) {
11
+ result[i] = result[i] * suffixProduct;
12
+ suffixProduct *= nums[i];
13
14
15
+ return result;
16
+}
0 commit comments