Skip to content

Commit 8271e1c

Browse files
committed
Time: 381 ms (24.46%), Space: 17.8 MB (33.15%) - LeetHub
1 parent b9da043 commit 8271e1c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# time complexity: O(n^2)
2+
# space complexity: O(1)
3+
from math import sqrt
4+
5+
6+
class Solution:
7+
def countTriples(self, n: int) -> int:
8+
count = 0
9+
for a in range(1, n + 1):
10+
for b in range(1, n + 1):
11+
c = int(sqrt(a**2 + b**2 + 1))
12+
if c <= n and a ** 2 + b ** 2 == c ** 2:
13+
count += 1
14+
return count
15+
16+
17+
n = 5
18+
print(Solution().countTriples(n))
19+
n = 10
20+
print(Solution().countTriples(n))

0 commit comments

Comments
 (0)