码迷,mamicode.com
首页 > 其他好文 > 详细

Search in Rotated Sorted Array II

时间:2014-11-22 22:52:33      阅读:262      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   os   sp   for   on   

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.

 

C++代码实现:

#include<iostream>
using namespace std;

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

int main()
{
    Solution s;
    int A[10]= {2,3,4,5,6,7,8,9,10,1};
    cout<<s.search(A,10,5)<<endl;
}

 

Search in Rotated Sorted Array II

标签:style   blog   io   ar   color   os   sp   for   on   

原文地址:http://www.cnblogs.com/wuchanming/p/4115704.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!