mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Merge branch 'youngyangyang04:master' into master
This commit is contained in:
@ -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:
|
||||
|
Reference in New Issue
Block a user