class Solution(object): def findMin(self, nums): if nums <= nums[-1]: return nums for i in range(len(nums)-1): if nums[i+1] < nums[i]: return nums[i+1]
Binary Search the time complexity will be
O(logn) while your solution will give us
O(n). Just imagine this case where you need to
frequently retrieve the
minimum in a set of large-scale different arrays. The difference will be huge. You should try to optimise it instead of just working it out, since you're here to improve yourself, right?
@LHearen you're right, thanks!