2037. Count Square Sum Triples
My accepted Python solution to LeetCode problem 2037, Count Square Sum Triples, running in 110ms.
- Difficulty: Easy
- Python
- Runtime 110ms
- Memory 17.2MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 110ms, memory 17.2MB, accepted 2025-12-30.
class Solution:
def countTriples(self, n: int) -> int:
count = 0
squares = set(i*i for i in range(1, n+1))
for a in range(1, n+1):
for b in range(1, n+1):
c_sq = a*a + b*b
if c_sq in squares:
count += 1
return count