Skip to content

Commit d8b93eb

Browse files
authored
Create 1726-tuple-with-same-product.js
1 parent 5a55ade commit d8b93eb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

1726-tuple-with-same-product.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
const tupleSameProduct = function(nums) {
6+
const m = {}
7+
const len = nums.length
8+
for(let i = 0; i < len - 1; i++) {
9+
for(let j = i + 1; j < len; j++) {
10+
const tmp = nums[i] * nums[j]
11+
if(m[tmp] == null) m[tmp] = 0
12+
m[tmp]++
13+
}
14+
}
15+
let res = 0
16+
Object.keys(m).forEach(e => {
17+
if(m[e] > 1) res += m[e] * (m[e] - 1) * 4
18+
})
19+
20+
return res
21+
};

0 commit comments

Comments
 (0)