mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
03adefc12a
commit
14f8cf47ec
|
@ -6,28 +6,31 @@ def find_peak_util(matrix, left, right, row_count):
|
||||||
if matrix[i][mid_col] > matrix[max_row_index][mid_col]:
|
if matrix[i][mid_col] > matrix[max_row_index][mid_col]:
|
||||||
max_row_index = i
|
max_row_index = i
|
||||||
|
|
||||||
|
if (
|
||||||
if (mid_col == 0 or matrix[max_row_index][mid_col] >= matrix[max_row_index][mid_col - 1]) and \
|
mid_col == 0
|
||||||
(mid_col == len(matrix[0]) - 1 or matrix[max_row_index][mid_col] >= matrix[max_row_index][mid_col + 1]):
|
or matrix[max_row_index][mid_col] >= matrix[max_row_index][mid_col - 1]
|
||||||
|
) and (
|
||||||
|
mid_col == len(matrix[0]) - 1
|
||||||
|
or matrix[max_row_index][mid_col] >= matrix[max_row_index][mid_col + 1]
|
||||||
|
):
|
||||||
return matrix[max_row_index][mid_col]
|
return matrix[max_row_index][mid_col]
|
||||||
|
|
||||||
|
if (
|
||||||
if mid_col > 0 and matrix[max_row_index][mid_col - 1] > matrix[max_row_index][mid_col]:
|
mid_col > 0
|
||||||
|
and matrix[max_row_index][mid_col - 1] > matrix[max_row_index][mid_col]
|
||||||
|
):
|
||||||
return find_peak_util(matrix, left, mid_col - 1, row_count)
|
return find_peak_util(matrix, left, mid_col - 1, row_count)
|
||||||
|
|
||||||
return find_peak_util(matrix, mid_col + 1, right, row_count)
|
return find_peak_util(matrix, mid_col + 1, right, row_count)
|
||||||
|
|
||||||
|
|
||||||
def find_peak(matrix):
|
def find_peak(matrix):
|
||||||
if not matrix or not matrix[0]:
|
if not matrix or not matrix[0]:
|
||||||
return None
|
return None
|
||||||
return find_peak_util(matrix, 0, len(matrix[0]) - 1, len(matrix))
|
return find_peak_util(matrix, 0, len(matrix[0]) - 1, len(matrix))
|
||||||
|
|
||||||
matrix = [
|
|
||||||
[10, 8, 10, 10],
|
matrix = [[10, 8, 10, 10], [14, 13, 12, 11], [15, 9, 11, 21], [16, 17, 19, 20]]
|
||||||
[14, 13, 12, 11],
|
|
||||||
[15, 9, 11, 21],
|
|
||||||
[16, 17, 19, 20]
|
|
||||||
]
|
|
||||||
|
|
||||||
peak = find_peak(matrix)
|
peak = find_peak(matrix)
|
||||||
print(f"Peak element is: {peak}")
|
print(f"Peak element is: {peak}")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user