https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/
1 class Solution { 2 public: 3 int findMin(vector<int>& nums) { 4 int size=nums.size(); 5 if(size==0) 6 return 0; 7 if(size==1) 8 return nums[0]; 9 int index1=0; 10 int index2=size-1; 11 if(nums[index1]<nums[index2]) 12 return nums[index1]; 13 int middle=(index1+index2)/2; 14 while(index1!=middle&&index2!=middle) 15 { 16 if(nums[middle]>nums[index2]) 17 { 18 index1=middle; 19 } 20 else 21 { 22 index2=middle; 23 } 24 middle=(index1+index2)/2; 25 } 26 return nums[index2]; 27 } 28 };