Leetcode练习(Python):数组类:第153题:假设按照升序排序的数组在预先未知的某个点上进行了旋转。 ( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。 请找出其中最小的元素。 你可以假设数组中不存在重复元素。

题目:
假设按照升序排序的数组在预先未知的某个点上进行了旋转。  ( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。  请找出其中最小的元素。  你可以假设数组中不存在重复元素。 
思路:
思路1,用函数,这样感觉有点不厚道;思路2,用二分法
程序1:
class Solution:
    def findMin(self, nums: List[int]) -> int:
        nums.sort()
        output = nums[0]
        return output
程序2:
class Solution:
    def findMin(self, nums: List[int]) -> int:
        length = len(nums)
        if length <= 0:
            return 0
        if length == 0:
            return nums[0]
        head = 0
        tail = length - 1
        while head < tail:
            middle = (head + tail) // 2
            if nums[middle] > nums[tail]:
                head = middle + 1
            else:
                tail = middle
        output = nums[head]
        return output