#在一个二维数组中每一行都是按照从左到右的顺序递增排序,每一列都是按从上到下的递增排序,完成一个函数判断该数组中是含有该数字
arr_v2 = [[1, 2, 8, 9], [2, 4, 9, 12], [4, 7, 10, 13], [6, 8, 11, 15]]
def findNumInV2arr(arr,num):
if arr is None or num is None or len(arr)==0:
return None
rows = len(arr) - 1
colunms = len(arr[0]) - 1
row = 0
while row <= rows and colunms >= 0:
if num == arr[row][colunms]:
print("在",row+1,"行",colunms+1,"列,找到了此数字")
break
elif a < arr[row][colunms]:
colunms -= 1
else:
row += 1
print(findNumInV2arr(arr_v2,9))
二维数组中的查找-python
最新推荐文章于 2021-04-29 18:57:08 发布