We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ed827e8 commit 86e71aeCopy full SHA for 86e71ae
1 file changed
1925-count-square-sum-triples.js
@@ -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