Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions leetcode/1901-2000/1925.Count-Square-Sum-Triples/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
# [1925.Count Square Sum Triples][title]

> [!WARNING|style:flat]
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)

## Description
A **square triple** `(a,b,c)` is a triple where `a`, `b`, and `c` are **integers** and `a^2 + b^2 = c^2`.

Given an integer `n`, return the number of **square triples** such that `1 <= a, b, c <= n`.

**Example 1:**

```
Input: a = "11", b = "1"
Output: "100"
Input: n = 5
Output: 2
Explanation: The square triples are (3,4,5) and (4,3,5).
```

## 题意
> ...

## 题解
**Example 2:**

### 思路1
> ...
Count Square Sum Triples
```go
```

Input: n = 10
Output: 4
Explanation: The square triples are (3,4,5), (4,3,5), (6,8,10), and (8,6,10).
```

## 结语

Expand Down
17 changes: 15 additions & 2 deletions leetcode/1901-2000/1925.Count-Square-Sum-Triples/Solution.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
package Solution

func Solution(x bool) bool {
return x
func Solution(n int) int {
cache := make(map[int]struct{})
for i := 1; i <= n; i++ {
cache[i*i] = struct{}{}
}

var ret int
for i := 1; i <= n-1; i++ {
for j := i + 1; j <= n; j++ {
if _, ok := cache[i*i+j*j]; ok {
ret += 2
}
}
}
return ret
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ func TestSolution(t *testing.T) {
// 测试用例
cases := []struct {
name string
inputs bool
expect bool
inputs int
expect int
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", 5, 2},
{"TestCase2", 10, 4},
}

// 开始测试
Expand All @@ -30,10 +29,10 @@ func TestSolution(t *testing.T) {
}
}

// 压力测试
// 压力测试
func BenchmarkSolution(b *testing.B) {
}

// 使用案列
// 使用案列
func ExampleSolution() {
}
Loading