Created
March 5, 2022 04:17
-
-
Save theabbie/7aa479c522daac50c4993d55a6657479 to your computer and use it in GitHub Desktop.
Check If Perfect Square
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def isPerfectSquare(num): | |
beg = 0 | |
end = num | |
while beg <= end: | |
mid = (beg + end) // 2 | |
if mid * mid == num: | |
return True | |
elif beg == end: | |
break | |
elif mid * mid > num: | |
end = mid | |
else: | |
beg = mid + 1 | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment