Find Minimum in Rotated Sorted Array
题目描述:
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
).
Find the minimum element.
You may assume no duplicate exists in the array.
题目大意:
找出数组中的最小值。
题目代码:
class Solution {
public:
int findMin(vector<int>& nums) {
int ans = INT_MAX;
for(int i = 0; i < nums.size(); i++){
ans = min(nums[i], ans);
}
return ans;
}
};