Skip to content

Commit 86e71ae

Browse files
authored
Create 1925-count-square-sum-triples.js
1 parent ed827e8 commit 86e71ae

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

1925-count-square-sum-triples.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {number} n
3+
* @return {number}
4+
*/
5+
const countTriples = function(n) {
6+
let res = 0
7+
const hash = {}
8+
for(let i = 1; i<= n; i++) {
9+
hash[i * i] = 1
10+
}
11+
12+
for(let i = 1; i <= n; i++) {
13+
for(let j = i; i * i + j * j <= n * n; j++) {
14+
res += (hash[i * i + j * j] || 0) * 2
15+
}
16+
}
17+
18+
return res
19+
};

0 commit comments

Comments
 (0)