diff --git a/problems/0035.搜索插入位置.md b/problems/0035.搜索插入位置.md index 5ed3ac56..4b17bec6 100644 --- a/problems/0035.搜索插入位置.md +++ b/problems/0035.搜索插入位置.md @@ -270,6 +270,26 @@ func searchInsert(nums []int, target int) int { } ``` +### Rust + +```rust +impl Solution { + pub fn search_insert(nums: Vec, 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: