Skip to content

Commit

Permalink
Merge pull request #856 from 0xff-dev/633
Browse files Browse the repository at this point in the history
Add solution and test-cases for problem 633
  • Loading branch information
6boris committed Jun 6, 2024
2 parents fdc40f4 + 9fe4fb3 commit 6bcf4e9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
22 changes: 8 additions & 14 deletions leetcode/601-700/0633.Sum-of-Square-Numbers/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
# [633.Sum of Square Numbers][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
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.

**Example 1:**

```
Input: a = "11", b = "1"
Output: "100"
Input: c = 5
Output: true
Explanation: 1 * 1 + 2 * 2 = 5
```

## 题意
> ...
## 题解
**Example 2:**

### 思路1
> ...
Sum of Square Numbers
```go
```

Input: c = 3
Output: false
```

## 结语

Expand Down
19 changes: 17 additions & 2 deletions leetcode/601-700/0633.Sum-of-Square-Numbers/Solution.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
package Solution

func Solution(x bool) bool {
return x
import "math"

func Solution(c int) bool {
end := int(math.Sqrt(float64(c)))
x := 0
for x <= end {
r := x*x + end*end
if r == c {
return true
}
if r < c {
x++
continue
}
end--
}
return false
}
12 changes: 6 additions & 6 deletions leetcode/601-700/0633.Sum-of-Square-Numbers/Solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ func TestSolution(t *testing.T) {
// 测试用例
cases := []struct {
name string
inputs bool
inputs int
expect bool
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", 5, true},
{"TestCase2", 3, false},
{"TestCase3", 4, true},
}

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

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

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

0 comments on commit 6bcf4e9

Please sign in to comment.