Skip to content

Commit c8d2d70

Browse files
authored
Merge pull request #1391 from 0xff-dev/1925
Add solution and test-cases for problem 1925
2 parents c277330 + 8649937 commit c8d2d70

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

leetcode/1901-2000/1925.Count-Square-Sum-Triples/README.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
# [1925.Count Square Sum Triples][title]
22

3-
> [!WARNING|style:flat]
4-
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)
5-
63
## Description
4+
A **square triple** `(a,b,c)` is a triple where `a`, `b`, and `c` are **integers** and `a^2 + b^2 = c^2`.
5+
6+
Given an integer `n`, return the number of **square triples** such that `1 <= a, b, c <= n`.
77

88
**Example 1:**
99

1010
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
11+
Input: n = 5
12+
Output: 2
13+
Explanation: The square triples are (3,4,5) and (4,3,5).
1314
```
1415

15-
## 题意
16-
> ...
17-
18-
## 题解
16+
**Example 2:**
1917

20-
### 思路1
21-
> ...
22-
Count Square Sum Triples
23-
```go
2418
```
25-
19+
Input: n = 10
20+
Output: 4
21+
Explanation: The square triples are (3,4,5), (4,3,5), (6,8,10), and (8,6,10).
22+
```
2623

2724
## 结语
2825

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
package Solution
22

3-
func Solution(x bool) bool {
4-
return x
3+
func Solution(n int) int {
4+
cache := make(map[int]struct{})
5+
for i := 1; i <= n; i++ {
6+
cache[i*i] = struct{}{}
7+
}
8+
9+
var ret int
10+
for i := 1; i <= n-1; i++ {
11+
for j := i + 1; j <= n; j++ {
12+
if _, ok := cache[i*i+j*j]; ok {
13+
ret += 2
14+
}
15+
}
16+
}
17+
return ret
518
}

leetcode/1901-2000/1925.Count-Square-Sum-Triples/Solution_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ func TestSolution(t *testing.T) {
1010
// 测试用例
1111
cases := []struct {
1212
name string
13-
inputs bool
14-
expect bool
13+
inputs int
14+
expect int
1515
}{
16-
{"TestCase", true, true},
17-
{"TestCase", true, true},
18-
{"TestCase", false, false},
16+
{"TestCase1", 5, 2},
17+
{"TestCase2", 10, 4},
1918
}
2019

2120
// 开始测试
@@ -30,10 +29,10 @@ func TestSolution(t *testing.T) {
3029
}
3130
}
3231

33-
// 压力测试
32+
// 压力测试
3433
func BenchmarkSolution(b *testing.B) {
3534
}
3635

37-
// 使用案列
36+
// 使用案列
3837
func ExampleSolution() {
3938
}

0 commit comments

Comments
 (0)