File tree 2 files changed +44
-0
lines changed
medium/sum of square numbers
2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Sum of Square Numbers
2
+
3
+ Given a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c.
4
+
5
+ Example 1:
6
+
7
+ ```
8
+ Input: c = 5
9
+ Output: true
10
+ Explanation: 1 * 1 + 2 * 2 = 5
11
+ ```
12
+
13
+ Example 2:
14
+
15
+ ```
16
+ Input: c = 3
17
+ Output: false
18
+ ```
19
+
20
+ ** Constraints:**
21
+ - 0 <= c <= 2^31 - 1
22
+
23
+ [ Link] ( https://leetcode.com/problems/sum-of-square-numbers/description/?envType=daily-question&envId=2024-06-17 )
Original file line number Diff line number Diff line change
1
+
2
+ class Solution :
3
+ def judgeSquareSum (self , c : int ) -> bool :
4
+ i = 2
5
+ while i * i <= c :
6
+ count = 0
7
+ if c % i == 0 :
8
+ while c % i == 0 :
9
+ count += 1
10
+ c /= i
11
+ if i % 4 == 3 and count % 2 != 0 :
12
+ return False
13
+ i += 1
14
+ return c % 4 != 3
15
+
16
+
17
+ s = Solution ()
18
+ print (s .judgeSquareSum (5 ))
19
+ print (s .judgeSquareSum (3 ))
20
+ print (s .judgeSquareSum (6 ))
21
+ print (s .judgeSquareSum (8 ))
You can’t perform that action at this time.
0 commit comments