From a22703d749f0d6267f1f800d147d7126661797b8 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 31 Oct 2024 20:22:27 +0000 Subject: [PATCH] =?UTF-8?q?Automated=20Commit=20=F0=9F=A4=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 +++++- index.html | 6 ++++ src/633-sum-of-square-numbers.md | 49 ++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/633-sum-of-square-numbers.md diff --git a/README.md b/README.md index f3de8da..c67a90a 100644 --- a/README.md +++ b/README.md @@ -35,4 +35,11 @@ LeetCode/ | 2239 | [Find Closest Number to Zero](https://leetcode.com/problems/find-closest-number-to-zero/description/) | [Python](src/2239-find-closest-number-to-zero.md) | | 1342 | [Number of Steps to Reduce a Number to Zero](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero/description/) | [Python](src/1342-number-of-steps-to-reduce-a-number-to-zero.md) | | 169 | [Majority Element](https://leetcode.com/problems/majority-element/description/) | [Python](src/169-majority-element.md) | -| 231 | [Power of Two](https://leetcode.com/problems/power-of-two/description/) | [Python](src/231-power-of-two.md) | \ No newline at end of file +| 231 | [Power of Two](https://leetcode.com/problems/power-of-two/description/) | [Python](src/231-power-of-two.md) | + + +## Medium + +| ID | Title | Solution | +|----|------------------------------------|----------| +| 633 | [Sum of Square Numbers](https://leetcode.com/problems/sum-of-square-numbers/description/) | [Python](src/633-sum-of-square-numbers.md) | \ No newline at end of file diff --git a/index.html b/index.html index 6e70583..8ad5732 100644 --- a/index.html +++ b/index.html @@ -76,6 +76,12 @@

Easy

| 169 | Majority Element | Python | | 231 | Power of Two | Python |

+

Medium

+ +

| ID | Title | Solution | +|----|------------------------------------|----------| +| 633 | Sum of Square Numbers | Python |

+ \ No newline at end of file diff --git a/src/633-sum-of-square-numbers.md b/src/633-sum-of-square-numbers.md new file mode 100644 index 0000000..07a4d59 --- /dev/null +++ b/src/633-sum-of-square-numbers.md @@ -0,0 +1,49 @@ +# Sum of Square Numbers +**URL**: [https://leetcode.com/problems/sum-of-square-numbers/description/](https://leetcode.com/problems/sum-of-square-numbers/description/) + +**Description:** + +Given a non-negative integer c, decide whether there're two integers a and b +such that a^2 + b^2 = c. + + __Example 1:__ +``` +Input: c = 5 +Output: true +Explanation: 1 * 1 + 2 * 2 = 5 +``` + + __Example 2:__ +``` +Input: c = 3 +Output: false +``` + + __Constraints:__ +``` +0 <= c <= 2^31 - 1 +``` + +**Solution Code**: +```python +from math import sqrt + +class Solution: + def judgeSquareSum(self, c: int) -> bool: + a = 0 + b = int(sqrt(c)) + + if c <= 2: + return True + + while (a<=b): + result = (a*a) + (b*b) + if result == c: + return True + if result < c: + a += 1 + else: + b -= 1 + return False + +```