LeetCode-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.

class Solution {
public:
    bool search(int A[], int n, int target) {
        if(n==0)return false;
        for(int i=0;i<n;i++){
            if(A[i]==target)return true;
        }
        return false;
    }
};

 

posted @ 2013-09-17 15:54  懒猫欣  阅读(91)  评论(0编辑  收藏  举报