9-line python clean code


  • 11
    2

    Just use binary search

    class Solution(object):
        def findMin(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            i = 0
            j = len(nums) - 1
            while i < j:
                m = i + (j - i) / 2
                if nums[m] > nums[j]:
                    i = m + 1
                else:
                    j = m
            return nums[i]

  • 0

    class Solution(object):
    def findMin(self, nums):
    """
    :type nums: List[int]
    :rtype: int
    """
    N = len(nums)
    if(N == 1):
    return nums[0]
    i = 0
    j = N - 1

        while(i < j):
            k = int((i + j) / 2)
            if(nums[k] < nums[j]):
                j = k
            else:
                i = k + 1
        return nums[i]
    

  • 0

    I think this question can be solved by binary search!
    Thank you for lighting ME!


  • 0
    R
    This post is deleted!

  • 0
    S
    This post is deleted!

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.