首页 > 其他 > 详细

Search in Rotated Sorted Array II

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

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!