Update README.md

This commit is contained in:
marina 2023-08-07 22:15:51 -07:00 committed by GitHub
parent c4e0cdc9ff
commit 3b3a40d782
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -136,3 +136,57 @@ def sqrt(x) -> int:
return right return right
``` ```
<br>
---
### find min in a rotated array
<br>
```python
def find_min(nums):
left, right = 0, len(nums) - 1
while nums[left] > nums[right]:
mid = (left + right) // 2
if nums[mid] < nums[right]:
right = mid
else:
left = mid + 1
return nums[left]
```
<br>
---
### find a peak element
<br>
* a peak element is an element that is strictly greater than its neighbors.
<br>
```python
def peak_element(nums):
left, right = 0, len(nums) - 1
while left < right:
mid = (left + right) // 2
if nums[mid + 1] < nums[mid]:
right = mid
else:
left = mid + 1
return left
```