20240719 Finished
This commit is contained in:
parent
f861459f2c
commit
942e8170b7
|
@ -177,4 +177,5 @@ mod p918_maximum_sum_circular_subarray;
|
||||||
mod p35_search_insert_position;
|
mod p35_search_insert_position;
|
||||||
mod p74_search_a_2d_matrix;
|
mod p74_search_a_2d_matrix;
|
||||||
mod p33_search_in_rotated_sorted_array;
|
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;
|
37
src/problem/p153_find_minimum_in_rotated_sorted_array.rs
Normal file
37
src/problem/p153_find_minimum_in_rotated_sorted_array.rs
Normal 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() {
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user