diff --git a/leetcode/601-700/0633.Sum-of-Square-Numbers/README.md b/leetcode/601-700/0633.Sum-of-Square-Numbers/README.md index d8ad1876d..f68c3e17d 100644 --- a/leetcode/601-700/0633.Sum-of-Square-Numbers/README.md +++ b/leetcode/601-700/0633.Sum-of-Square-Numbers/README.md @@ -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 a2 + b2 = 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 +``` ## 结语 diff --git a/leetcode/601-700/0633.Sum-of-Square-Numbers/Solution.go b/leetcode/601-700/0633.Sum-of-Square-Numbers/Solution.go index d115ccf5e..30e7f49c3 100644 --- a/leetcode/601-700/0633.Sum-of-Square-Numbers/Solution.go +++ b/leetcode/601-700/0633.Sum-of-Square-Numbers/Solution.go @@ -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 } diff --git a/leetcode/601-700/0633.Sum-of-Square-Numbers/Solution_test.go b/leetcode/601-700/0633.Sum-of-Square-Numbers/Solution_test.go index 14ff50eb4..167c7a03b 100644 --- a/leetcode/601-700/0633.Sum-of-Square-Numbers/Solution_test.go +++ b/leetcode/601-700/0633.Sum-of-Square-Numbers/Solution_test.go @@ -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}, } // 开始测试 @@ -30,10 +30,10 @@ func TestSolution(t *testing.T) { } } -// 压力测试 +// 压力测试 func BenchmarkSolution(b *testing.B) { } -// 使用案列 +// 使用案列 func ExampleSolution() { }