class Solution {
public:
int findMin(vector<int>& nums) {
int left = -1, right = nums.size() - 1;
while (left + 1 < right && nums[right] == nums[0]) right--;
if (nums[0] <= nums[right]) return nums[0];
while (left + 1 < right) {
int mid = left + right >> 1;
if (nums[mid] >= nums[0]) left = mid;
else right = mid;
}
return left == nums.size() - 1 ? nums[0] : nums[left + 1];
}
};