题目描述:

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

 

posted on 2018-03-18 22:15  宵夜在哪  阅读(58)  评论(0编辑  收藏  举报