class Solution: # @param num, a list of integer # @return an integer def findPeakElement(self, num): n=len(num) i=0 greatestVar=num greatestIndex=0 while i<n-1: if greatestVar>num[i]: i=i+1 elif n==1: greatestIndex=0 else: greatestVar=num[i] greatestIndex=i i=i+1 return greatestIndex
Python code that almost works. Doesn't work for test case 51. Can anyone spot the problem?
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.