LeetCode 33 Search in Rotated Sorted Array (Search in the rotating sorting Array )(*)
Translation
Suppose an array is rotated at an unknown axis point. For example, 0 1 2 4 5 6 7 may change to 4 5 6 7 0 1 2. Search for the target value. If the target value is found, its index is returned. Otherwise,-1 is returned. You can assume that no repeated elements exist in the array.
Original
Suppose a sorted array 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.
Code
class Solution {public: int search(vector
& nums, int target) { int l = 0, r = nums.size()-1; while (l<=r) { int mid = (r-l)/2+l; if (nums[mid] == target) return mid; if (nums[mid] < nums[r]) { if (nums[mid]