mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-30 04:36:08 -04:00
Update README.md
This commit is contained in:
parent
e63cfe856f
commit
b52c7e0d03
@ -102,3 +102,37 @@ def binary_search_matrix(matrix, item, lower=0, higher=None):
|
|||||||
|
|
||||||
return False
|
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
|
||||||
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user