#Def leftbottom(target, array) found from the lower left corner : line_num= len (array) #represents line col_num= len (array[ 0 ]) #represents column #first search from the lower left corner col= 0 line=line_num- 1 while col<col_num and line>= 0 : if target<array [line][col]: line-=1 elif target>array[line][col]: col+= 1 else : return True return False #Search from the upper right corner, the left ones are smaller than this element, and the lower ones are bigger than this element def righttop_find(arr,target): #Define line line_num= len (arr) #Define Column col_num= len (arr[ 0 ]) #define the upper right corner element i= 0 j=col_num- 1 while i<line_num and j>= 0 : if target<arr[i][j]: j-=1 elif target>arr[i][j]: i+=1 else: return True return False
Python implements two-dimensional array search (5-7)
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325847037&siteId=291194637
Recommended
Ranking