Skip to content

Commit 3fa6885

Browse files
authored
Update Solution.rs
1 parent 94ddcbd commit 3fa6885

File tree

1 file changed

+9
-16
lines changed
  • solution/0000-0099/0035.Search Insert Position

1 file changed

+9
-16
lines changed
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
1-
use std::cmp::Ordering;
21
impl Solution {
32
pub fn search_insert(nums: Vec<i32>, target: i32) -> i32 {
4-
let mut left = 0;
5-
let mut right = nums.len();
6-
while left < right {
7-
let mid = left + (right - left) / 2;
8-
match nums[mid].cmp(&target) {
9-
Ordering::Less => {
10-
left = mid + 1;
11-
}
12-
Ordering::Greater => {
13-
right = mid;
14-
}
15-
Ordering::Equal => {
16-
return mid as i32;
17-
}
3+
let mut l: usize = 0;
4+
let mut r: usize = nums.len();
5+
while l < r {
6+
let mid = (l + r) >> 1;
7+
if nums[mid] >= target {
8+
r = mid;
9+
} else {
10+
l = mid + 1;
1811
}
1912
}
20-
left as i32
13+
l as i32
2114
}
2215
}

0 commit comments

Comments
 (0)