mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Update sqrt_x.py
This commit is contained in:
parent
855ecff683
commit
e63cfe856f
@ -12,16 +12,16 @@ def sqrt(x) -> int:
|
||||
|
||||
while left <= right:
|
||||
|
||||
pivot = left + (right - left) // 2
|
||||
num = pivot * pivot
|
||||
mid = (right + left) // 2
|
||||
num = mid * mid
|
||||
|
||||
if num > x:
|
||||
right = pivot - 1
|
||||
right = mid - 1
|
||||
|
||||
elif num < x:
|
||||
left = pivot + 1
|
||||
left = mid + 1
|
||||
|
||||
else:
|
||||
return pivot
|
||||
return mid
|
||||
|
||||
return right
|
||||
|
Loading…
x
Reference in New Issue
Block a user