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 cd864f8 commit 9440022Copy full SHA for 9440022
238.除自身以外数组的乘积.js
@@ -0,0 +1,15 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @return {number[]}
4
+ */
5
+var productExceptSelf = function(nums) {
6
+ const a = [nums[0]];
7
+ const b = [nums[nums.length - 1]];
8
+ for (let i = 1; i < nums.length; i++) {
9
+ a.push(a[i - 1] * nums[i]);
10
+ b.push(b[i - 1] * nums[nums.length -1 - i]);
11
+ }
12
+ return nums.map((n, i) => {
13
+ return (a[i - 1] === undefined ? 1 : a[i - 1]) * (b[b.length - 2 - i] === undefined ? 1 : b[b.length - 2 - i]);
14
+ })
15
+};
0 commit comments