LeetCode 704. Binary Search

Problem Statement


impl Solution {
pub fn search(nums: Vec<i32>, target: i32) -> i32 {
let (mut left, mut right) = (0, nums.len());
while left < right {
let mid = left + (right - left) / 2;
if nums[mid] == target {
return mid as i32;
} else if nums[mid] < target {
left = mid + 1;
} else {
right = mid;
}
}
return -1;
}
}