Skip to content

Commit

Permalink
lc: Fix lint warning
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Nov 29, 2023
1 parent 605575b commit 5145754
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions leetcode/704.binary_search/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

//! Problem: [binary search](https://leetcode.com/problems/binary-search)
use std::cmp::Ordering;

pub fn solution1(nums: &[i32], target: i32) -> i32 {
if nums.is_empty() {
return -1;
Expand All @@ -13,13 +15,11 @@ pub fn solution1(nums: &[i32], target: i32) -> i32 {
let mut high = nums.len() - 1;
while low + 1 < high {
let middle = low + (high - low) / 2;
println!("low: {low}, high: {high}, middle: {middle}");
if nums[middle] < target {
low = middle;
} else if nums[middle] == target {
return middle as i32;
} else if nums[middle] > target {
high = middle;
//println!("low: {low}, high: {high}, middle: {middle}");
match nums[middle].cmp(&target) {
Ordering::Less => low = middle,
Ordering::Equal => return middle as i32,
Ordering::Greater => high = middle,
}
}
-1
Expand Down

0 comments on commit 5145754

Please sign in to comment.