Skip to content

Commit ffb5084

Browse files
committed
寻找峰值
1 parent 693752d commit ffb5084

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

find_peak_element.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: utf-8 -*-
2+
3+
class Solution:
4+
#@param A: An integers list.
5+
#@return: return any of peek positions.
6+
def findPeak(self, A):
7+
# write your code here
8+
ret = -1
9+
for i in xrange(len(A)):
10+
left = A[i - 1] if (i - 1) >= 0 else -2147483648
11+
right = A[i + 1] if (i + 1) < len(A) else -2147483648
12+
if A[i] > max(left, right):
13+
if ret == -1:
14+
ret = i
15+
elif A[i] > A[ret]:
16+
ret = i
17+
return ret

0 commit comments

Comments
 (0)