![JAR search and dependency download from the Maven repository](/logo.png)
g1901_2000.s1925_count_square_sum_triples.Solution.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-kotlin Show documentation
Show all versions of leetcode-in-kotlin Show documentation
Kotlin-based LeetCode algorithm problem solutions, regularly updated
package g1901_2000.s1925_count_square_sum_triples
// #Easy #Math #Enumeration #2023_06_20_Time_161_ms_(40.00%)_Space_33.4_MB_(80.00%)
class Solution {
fun countTriples(n: Int): Int {
var count = 0
for (i in 1 until n) {
for (j in 1 until n) {
val product = i * i + j * j
val sq = Math.sqrt(product.toDouble())
if (sq <= n && sq - Math.floor(sq) == 0.0) {
count++
}
}
}
return count
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy