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.
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; }