Skip to content

Commit 8de16f4

Browse files
committed
367
1 parent e13e64d commit 8de16f4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

367_Valid_Perfect_Square.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution(object):
2+
def isPerfectSquare(self, num):
3+
"""
4+
:type num: int
5+
:rtype: bool
6+
"""
7+
left, right = 1, num
8+
while left <= right:
9+
mid = (left + right) / 2
10+
r = mid * mid
11+
if r < num:
12+
left = mid + 1
13+
elif r > num:
14+
right = mid - 1
15+
else:
16+
return True
17+
return False

0 commit comments

Comments
 (0)