Skip to content

Commit 9fe4fb3

Browse files
committed
Add solution and test-cases for problem 633
1 parent 09a1dcb commit 9fe4fb3

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

leetcode/601-700/0633.Sum-of-Square-Numbers/README.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
# [633.Sum of Square Numbers][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+
Given a non-negative integer `c`, decide whether there're two integers `a` and `b` such that a<sup>2</sup> + b<sup>2</sup> = c.
75

86
**Example 1:**
97

108
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
9+
Input: c = 5
10+
Output: true
11+
Explanation: 1 * 1 + 2 * 2 = 5
1312
```
1413

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

20-
### 思路1
21-
> ...
22-
Sum of Square Numbers
23-
```go
2416
```
25-
17+
Input: c = 3
18+
Output: false
19+
```
2620

2721
## 结语
2822

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

3-
func Solution(x bool) bool {
4-
return x
3+
import "math"
4+
5+
func Solution(c int) bool {
6+
end := int(math.Sqrt(float64(c)))
7+
x := 0
8+
for x <= end {
9+
r := x*x + end*end
10+
if r == c {
11+
return true
12+
}
13+
if r < c {
14+
x++
15+
continue
16+
}
17+
end--
18+
}
19+
return false
520
}

leetcode/601-700/0633.Sum-of-Square-Numbers/Solution_test.go

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

2121
// 开始测试
@@ -30,10 +30,10 @@ func TestSolution(t *testing.T) {
3030
}
3131
}
3232

33-
// 压力测试
33+
// 压力测试
3434
func BenchmarkSolution(b *testing.B) {
3535
}
3636

37-
// 使用案列
37+
// 使用案列
3838
func ExampleSolution() {
3939
}

0 commit comments

Comments
 (0)