Clean python code


  • -2
    R
    class Solution:
        # @param num, a list of integer
        # @return an integer
        def findMin(self, num):
            if len(num)==1:
                return num[0]
            else:
                for i in range(1,len(num)):
                    if num[i-1]>num[i]:
                        if num[i]<=num[0]:
                            return num[i]
                return num[0]

  • 0
    M

    You are essentially performing a linear search for the pivot point, if I am not mistaken (i.e. O(N)). Your algorithm can be upgraded to run in logarithmic time.


  • 0
    D

    If using a linear search, can just use min(num)... This question is supposed to be done in binary search.


Log in to reply
 

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