MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / findPeakElement

Method findPeakElement

Array/FindPeakElement.py:36–55  ·  view source on GitHub ↗

:type nums: List[int] :rtype: int

(self, nums)

Source from the content-addressed store, hash-verified

34"""
35class Solution(object):
36 def findPeakElement(self, nums):
37 """
38 :type nums: List[int]
39 :rtype: int
40 """
41
42 length = len(nums)
43
44 for i in range(1, length-1):
45 if nums[i-1] < nums[i] > nums[i+1]:
46 return i
47
48 if length <= 2:
49 return nums.index(max(nums))
50 else:
51 if nums[0] > nums[1]:
52 return 0
53 elif nums[-1] > nums[-2]:
54 return length-1
55 return None

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected