题目链接:https://www.lintcode.com/problem/find-minimum-in-rotated-sorted-array/description
/**
* @param nums: a rotated sorted array
* @return: the minimum number in the array
*/
func findMin(nums []int) int {
// write your code here
if (nums == nil || len(nums) == 0) {
return -1;
}
var start int = 0;
var end int = len(nums) - 1;
var target = nums[len(nums)-1]
for {
if (start+1 >= end) {
break;
}
var mid int = (start + end) / 2;
if (nums[mid] <= target) {
end = mid;
} else {
start = mid;
}
}
return min(nums[start], nums[end]);
}
func min(x int, y int) int {
if (x < y) {
return x;
}
return y;
}
func main() {
var nums1 = []int{4, 5, 6, 7, 0, 1, 2};
var min1 = findMin(nums1);
fmt.Println(min1);
}