题目描述:
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7
might become 4 5 6 7 0 1 2
).
Write a function to determine if a given target is in the array.
The array may contain duplicates.
解题思路:
还是一个个遍历过去。。。
代码:
1 class Solution { 2 public: 3 bool search(vector<int>& nums, int target) { 4 int n = nums.size(); 5 for(int i = 0; i < n; i++){ 6 if(nums[i] == target) 7 return true; 8 } 9 return false; 10 } 11 };