Skip to content

Commit

Permalink
Merge branch 'youngyangyang04:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
vanyongqi committed Sep 21, 2022
2 parents 5da89e2 + 0cfd797 commit 190f790
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions problems/0035.搜索插入位置.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 190f790

Please sign in to comment.