My Python code(Best 32ms, Worst 52ms)


  • 0
    C
    class Solution(object):
        def findPeakElement(self, nums):
            j=len(nums)-1
            i=0
            while i<j:
                if nums[i+1]>nums[i]:
                    i+=1
                else:
                    return i
                if nums[j-1]>nums[j]:
                    j-=1
                else:
                    return j
            return j
    

  • 0
    P

    its not in logarithmic time


Log in to reply
 

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