Skip to content

Instantly share code, notes, and snippets.

@theabbie
Created March 5, 2022 04:17
Show Gist options
  • Save theabbie/7aa479c522daac50c4993d55a6657479 to your computer and use it in GitHub Desktop.
Save theabbie/7aa479c522daac50c4993d55a6657479 to your computer and use it in GitHub Desktop.
Check If Perfect Square
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