Merge branch 'youngyangyang04:master' into master

This commit is contained in:
vanyongqi
2022-09-21 14:01:15 +08:00
committed by GitHub

View File

@ -270,6 +270,26 @@ func searchInsert(nums []int, target int) int {
}
```
### Rust
```rust
impl Solution {
pub fn search_insert(nums: Vec<i32>, target: i32) -> i32 {
let mut left = 0;
let mut right = nums.len();
while left < right {
let mid = (left + right) / 2;
match nums[mid].cmp(&target) {
Ordering::Less => left = mid + 1,
Ordering::Equal => return ((left + right) / 2) as i32,
Ordering::Greater => right = mid,
}
}
((left + right) / 2) as i32
}
}
```
### Python
```python
class Solution: