81.Search in Rotated Sorted Array II

Posted smallredness

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了81.Search in Rotated Sorted Array II相关的知识,希望对你有一定的参考价值。

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

以上是关于81.Search in Rotated Sorted Array II的主要内容,如果未能解决你的问题,请参考以下文章

#Leetcode# 81. Search in Rotated Sorted Array II

81. Search in Rotated Sorted Array II

[Leetcode]81. Search in Rotated Sorted Array II

81. Search in Rotated Sorted Array II

81. Search in Rotated Sorted Array II

81. Search in Rotated Sorted Array II