A relative concise Python code

  • 1
    class Solution:
        # @param num, a list of integer
        # @return an integer
        def findPeakElement(self, num):
            l,r = 0,len(num)-1
            while l < r:
                mid = (l+r)/2
                if num[mid] < num[mid+1]:
                    l = mid+1
                elif num[mid] > num[mid+1]:
                    r = mid
            return r

  • 0

    Can you explain the algorithm behind this program ?

Log in to reply

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