Update README.md

This commit is contained in:
marina 2023-08-07 21:49:23 -07:00 committed by GitHub
parent e63cfe856f
commit b52c7e0d03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -102,3 +102,37 @@ def binary_search_matrix(matrix, item, lower=0, higher=None):
return False
```
<br>
---
### find the square root
<br>
```python
def sqrt(x) -> int:
if x < 2:
return x
left, right = 2, x // 2
while left <= right:
mid = (right + left) // 2
num = mid * mid
if num > x:
right = mid - 1
elif num < x:
left = mid + 1
else:
return mid
return right
```