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 1ec4f10 commit 0476d33Copy full SHA for 0476d33
math/0367 Valid Perfect Square.md
@@ -0,0 +1,28 @@
1
+# 367. Valid Perfect Square
2
+https://leetcode-cn.com/problems/valid-perfect-square/
3
+Given a positive integer num, write a function which returns True if num is a perfect square else False.
4
+Follow up: Do not use any built-in library function such as sqrt.
5
+
6
7
+Example 1:
8
+Input: num = 16
9
+Output: true
10
11
+Example 2:
12
+Input: num = 14
13
+Output: false
14
15
+Constraints:
16
+1 <= num <= 2^31 - 1
17
18
+``` python3
19
+class Solution:
20
+ def isPerfectSquare(self, num: int) -> bool:
21
+ x0=num
22
+ while True:
23
+ x1=0.5*(x0+num/x0)
24
+ if x0-x1<1e-7:
25
+ break
26
+ x0=x1
27
+ return int(x0)*int(x0)==num
28
+```
0 commit comments