We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 71740f0 commit 559b6baCopy full SHA for 559b6ba
Leetcode_30day_challenge/August_Challenge_2021/Day-25_Sum_of_Squares.py
@@ -0,0 +1,34 @@
1
+# Solution - 1: PreComputation
2
+class Solution:
3
+ def judgeSquareSum(self, c: int) -> bool:
4
+ threshold = (1<<31) - 1
5
+ pre = set()
6
+ i = 0
7
+ while True:
8
+ temp = i*i
9
+ if temp > threshold:
10
+ break
11
+ else:
12
+ pre.add(temp)
13
+ i += 1
14
+
15
+ for i in pre:
16
+ val = c - i
17
+ if val in pre:
18
+ return True
19
20
+ return False
21
22
23
24
+# Solution - 2
25
+import math
26
27
28
29
+ for a in range(int(math.sqrt(c))+1):
30
+ b = math.sqrt(c - a*a)
31
+ if b == int(b):
32
33
34
0 commit comments