31 lines
747 B
Python
31 lines
747 B
Python
class Solution(object):
|
|
def findPeakElement(self, nums):
|
|
"""
|
|
:type nums: List[int]
|
|
:rtype: int
|
|
"""
|
|
if not nums:
|
|
return -1
|
|
|
|
if len(nums) == 1:
|
|
return 0
|
|
|
|
import sys
|
|
peak_value = -sys.maxint - 1
|
|
peak_index = -1
|
|
|
|
for i in range(0,len(nums)):
|
|
if i == 0 and nums[i] > nums[i+1]:
|
|
peak_index = i
|
|
break
|
|
elif i == len(nums)-1 and nums[i] > nums[i-1]:
|
|
peak_index = i
|
|
break
|
|
elif nums[i] > nums[i-1] and nums[i] > nums[i+1]:
|
|
peak_index = i
|
|
break
|
|
else:
|
|
pass
|
|
|
|
return peak_index
|