-
BingoPython解法一:二分法
class Solution(object): def findMin(self, nums): """ :type nums: List[int] :rtype: int """ low, high = 0, len(nums) - 1 while low < high: mid = (low + high) / 2 if nums[mid] <= nums[high]: #min位于左侧上升沿 high = mid else: #min位于左侧上升沿与右侧上升沿之间 low = mid + 1 return nums[low]
-
BingoPython解法二:线性枚举法
class Solution: # @param num, a list of integer # @return an integer def findMin(self, num): return min(num)
-
BingoC++:
class Solution { public: int findMin(vector<int> &num) { int left = 0, right = num.size() - 1; if (num[left] > num[right]) { while (left != (right - 1)) { int mid = (left + right) / 2; if (num[left] < num[mid]) left = mid; else right = mid; } return min(num[left], num[right]); } return num[0]; } };
-