题目描述:
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
).
You are given a target value to search. If found in the array return its index, otherwise return -1.
You may assume no duplicate exists in the array.
解题思路:
直接遍历搜索。。。
代码:
1 class Solution { 2 public: 3 int search(vector<int>& nums, int target) { 4 int n = nums.size(); 5 for(int i = 0; i < n; i++) 6 { 7 if(nums[i] == target) 8 return i; 9 } 10 return -1; 11 } 12 };