Skip to content

Commit

Permalink
Solution to #9
Browse files Browse the repository at this point in the history
  • Loading branch information
bharatr21 committed May 9, 2020
1 parent 39dfa52 commit 8e46e92
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Solutions/S09.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution:
# Has some issues with integer overflow in C++
def isPerfectSquare(self, num: int) -> bool:
if(num == 1):
return True
else:
b = 1
l = num
while (b <= l):
m = b + (l - b) // 2
if m * m == num:
return True
elif m * m < num and (m+1)*(m+1) > num:
return False
elif m * m < num:
b = m + 1
else:
l = m - 1

0 comments on commit 8e46e92

Please sign in to comment.