Skip to content

Commit 41915b7

Browse files
committed
042
1 parent 69ee047 commit 41915b7

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

041.search-in-sorted-matrix.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
inp = [[1,2,3],[4,5,6],[7,8,9]]
2+
3+
def searchInSortedMatrix(matrix, searchValue):
4+
col = 0;row = len(matrix[-1])-1
5+
while(row>=0 and col<len(matrix)):
6+
if matrix[row][col] < searchValue:
7+
col+=1
8+
elif matrix[row][col] > searchValue:
9+
row-=1
10+
else:
11+
return (row,col)
12+
return (-1,-1)
13+
14+
print(searchInSortedMatrix(inp,4))
File renamed without changes.

0 commit comments

Comments
 (0)