__author__ = 'nitin'
def find_elem_sorted_matrix(mat,M,N,elem):
row=0
col=N-1
while row=0:
if mat[row][col]==elem:
return True
elif mat[row][col]>elem:
col=col-1
else:
row=row+1
return False
amatrix=[[3,5,8],[6,7,10],[9,11,12]]
rows=len(amatrix)
cols=len(amatrix[0])
print find_elem_sorted_matrix(amatrix,rows,cols,8)
def find_elem_sorted_matrix(mat,M,N,elem):
row=0
col=N-1
while row
if mat[row][col]==elem:
return True
elif mat[row][col]>elem:
col=col-1
else:
row=row+1
return False
amatrix=[[3,5,8],[6,7,10],[9,11,12]]
rows=len(amatrix)
cols=len(amatrix[0])
print find_elem_sorted_matrix(amatrix,rows,cols,8)
No comments:
Post a Comment