Skip to content

Commit 3d9d00b

Browse files
committed
Time: 2 ms (96.6%), Space: 70.7 MB (56.73%) - LeetHub
source:7e69ced30b0284e915e6f2632204103740a1ad27
1 parent f3ba9c5 commit 3d9d00b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number[]}
4+
*/
5+
var productExceptSelf = function(nums) {
6+
let product = 1;
7+
const ans= [];
8+
// 왼쪽 곱
9+
for(let i=0;i<nums.length;i++){
10+
ans[i] = product;
11+
product *= nums[i];
12+
}
13+
14+
//오른쪽 곱
15+
product=1;
16+
for(let i=nums.length-1;i>=0;i--){
17+
ans[i] *= product;
18+
product *= nums[i];
19+
}
20+
21+
return ans;
22+
};

0 commit comments

Comments
 (0)