// compare the mid with the nums[right]
class Solution {
public:
int findMin(vector<int>& nums) {
// be aware of the right, if right is nums.size(), it will overflow the array
int left = 0, right = nums.size() - 1;
while (left < right) {
// if the sub array is not rottated, return the first element.
if (nums[left] < nums[right]) return nums[left];
int mid = left + (right - left) / 2;
if (nums[mid] < nums[right]) {
right = mid;
} else {
left = mid + 1;
}
}
return nums[left];
}
};