81. Search in Rotated Sorted Array II Medium

@problem@discussion
#Array#Binary Search



1/**
2 * [81] Search in Rotated Sorted Array II
3 *
4 * There is an integer array nums sorted in non-decreasing order (not necessarily with distinct values).
5 * Before being passed to your function, nums is rotated at an unknown pivot index k (0 <= k < nums.length) such that the resulting array is [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]] (0-indexed). For example, [0,1,2,4,4,4,5,6,6,7] might be rotated at pivot index 5 and become [4,5,6,6,7,0,1,2,4,4].
6 * Given the array nums after the rotation and an integer target, return true if target is in nums, or false if it is not in nums.
7 * You must decrease the overall operation steps as much as possible.
8 *  
9 * Example 1:
10 * Input: nums = [2,5,6,0,0,1,2], target = 0
11 * Output: true
12 * Example 2:
13 * Input: nums = [2,5,6,0,0,1,2], target = 3
14 * Output: false
15 *  
16 * Constraints:
17 * 
18 * 	1 <= nums.length <= 5000
19 * 	-10^4 <= nums[i] <= 10^4
20 * 	nums is guaranteed to be rotated at some pivot.
21 * 	-10^4 <= target <= 10^4
22 * 
23 *  
24 * Follow up: This problem is similar to <a href="/problems/search-in-rotated-sorted-array/description/" target="_blank">Search in Rotated Sorted Array</a>, but nums may contain duplicates. Would this affect the runtime complexity? How and why?
25 * 
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/search-in-rotated-sorted-array-ii/
30// discuss: https://leetcode.com/problems/search-in-rotated-sorted-array-ii/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35    pub fn search(nums: Vec<i32>, target: i32) -> bool {
36        false
37    }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn test_81() {
48    }
49}
50


Back
© 2025 bowen.ge All Rights Reserved.