Search a Rotated Array With Duplicates
Search a rotated sorted array that may contain repeated values.
The problem
Implement Solution.search(nums, target). nums holds between 1 and 5,000 integers. It was sorted in nondecreasing order, may contain repeated values, and was then rotated at an unknown point, so [0, 1, 2, 2, 4, 5] might become [2, 4, 5, 0, 1, 2]. Return True if target is in nums and False otherwise. Use binary search: discard half of the remaining range whenever the values tell you which half cannot hold target.
Starter code
class Solution:
def search(self, nums, target):
passPublic examples
nums = [2, 5, 6, 0, 0, 1, 2], target = 0givesTruenums = [4, 5, 6, 1, 2], target = 5givesTruenums = [4, 5, 6, 1, 2], target = 3givesFalse
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
