Search in Rotated Sorted Array II

IF
AlgoAxiomStaff Engineers
JSTS
Medium20 mins

Given an integer array nums sorted in ascending order which may contain duplicates, and is possibly rotated at an unknown pivot, return true if target is in nums, or false otherwise.

You must decrease the overall operation steps as much as possible.

Examples

Example 1:

Input: nums = [2, 5, 6, 0, 0, 1, 2], target = 0

Output: true

Example 2:

Input: nums = [2, 5, 6, 0, 0, 1, 2], target = 3

Output: false

Constraints

  • 1 <= nums.length <= 5000
  • -10^4 <= nums[i] <= 10^4
  • nums is sorted and rotated between 1 and n times
  • -10^4 <= target <= 10^4
Source: Modified Binary Search pattern — AlgoAxiom
JavaScript
Test Case 1
root = [1, 2, 3]
Test Case 2
root = [1, 2, 3, 4, 5]
Idle