81. Search in Rotated Sorted Array II

Practice Search in Rotated Sorted Array II for free on NudgeCode: Medium, Binary Search pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

An array sorted in non-decreasing order (duplicates allowed) was rotated at some unknown pivot, so [0,1,2,4,4,5,6] might become [4,5,6,0,1,2,4]. Given the rotated array nums and a value target, return true if target appears in it and false otherwise.

Try to do better than a linear scan when possible. Duplicates can force O(n) in the worst case.

Example

nums = [2,5,6,0,0,1,2], target = 0  ->  true
nums = [2,5,6,0,0,1,2], target = 3  ->  false

Constraints