Skip to content

Commit 798d00d

Browse files
authored
Update find-a-peak-element-ii.py
1 parent e8813a6 commit 798d00d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Python/find-a-peak-element-ii.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ def findPeakGrid(self, mat):
88
:rtype: List[int]
99
"""
1010
def get_vec(mat, i):
11-
return mat[i] if len(mat) < len(mat[0]) else (mat[j][i] for j in xrange(len(mat)))
11+
return mat[i] if len(mat) > len(mat[0]) else (mat[j][i] for j in xrange(len(mat)))
1212

1313
def check(mat, x):
1414
return max(get_vec(mat, x)) > max(get_vec(mat, x+1))
1515

16-
left, right = 0, (min(len(mat), len(mat[0]))-1)-1
16+
left, right = 0, (max(len(mat), len(mat[0]))-1)-1
1717
while left <= right:
1818
mid = left + (right-left)//2
1919
if check(mat, mid):
2020
right = mid-1
2121
else:
2222
left = mid+1
2323
max_left = max(get_vec(mat, left))
24-
return [left, next(i for i, x in enumerate(get_vec(mat, left)) if x == max_left)][::1 if len(mat) < len(mat[0]) else -1]
24+
return [left, next(i for i, x in enumerate(get_vec(mat, left)) if x == max_left)][::1 if len(mat) > len(mat[0]) else -1]
25+

0 commit comments

Comments
 (0)