20240719 Finished

This commit is contained in:
jackfiled 2024-07-19 11:05:42 +08:00
parent f861459f2c
commit 942e8170b7
2 changed files with 39 additions and 1 deletions

View File

@ -177,4 +177,5 @@ mod p918_maximum_sum_circular_subarray;
mod p35_search_insert_position;
mod p74_search_a_2d_matrix;
mod p33_search_in_rotated_sorted_array;
mod p34_find_first_and_last_position_of_element_in_sorted_array;
mod p34_find_first_and_last_position_of_element_in_sorted_array;
mod p153_find_minimum_in_rotated_sorted_array;

View File

@ -0,0 +1,37 @@
/**
* [153] Find Minimum in Rotated Sorted Array
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn find_min(nums: Vec<i32>) -> i32 {
let n = nums.len();
let (mut left, mut right) = (0, n);
while left < right {
let middle = (right - left) / 2 + left;
if nums[middle] > nums[n - 1] {
left = middle + 1;
} else {
right = middle;
}
}
nums[left]
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_153() {
}
}