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 5e2178f commit b83f655Copy full SHA for b83f655
product-of-array-except-self/casentino.ts
@@ -0,0 +1,14 @@
1
+function productExceptSelf(nums: number[]): number[] {
2
+ const len = nums.length;
3
+ const result = new Array(len).fill(1);
4
+ let pre = 1;
5
+ let post = 1;
6
+ for (let i = 0; i < len; i++) {
7
+ result[i] *= pre;
8
+ pre *= nums[i];
9
+
10
+ result[len - i - 1] *= post;
11
+ post *= nums[len - i - 1];
12
+ }
13
+ return result;
14
+}
0 commit comments