在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。
1 # -*- coding:utf-8 -*- 2 class Solution: 3 # array 二维列表 4 def Find(self, target, array): 5 row = len(array) 6 column = len(array[0]) 7 i,j = 0,column-1 8 while i < row and j >= 0: 9 if array[i][j] == target:10 return True11 elif array[i][j] > target:12 j -= 113 else:14 i += 115 return False16 # write code here
从右上角开始查询,其同行的元素,左边小右边大。其同列的元素,上边小下边大。