LeetCode OJ:Search in Rotated Sorted Array II

Search in Rotated Sorted Array II

 

Follow up for "Search in Rotated Sorted Array":
What if duplicates are allowed?

Would this affect the run-time complexity? How and why?

Write a function to determine if a given target is in the array.

算法思想:

Search in Rotated Sorted Array

类似,只是需要对相等的元素进行单独处理

class Solution {
public:
    bool search(int A[], int n, int target) {
        int left=0,right=n-1;
        while(left<=right){
            int mid=(left+right)/2;
            if(A[left]


你可能感兴趣的:(LeetCode)