题目描述
在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。
方法一:
class Solution:
def Find(self, target, array):
for i in range(len(array)):
if target in array[i]:
return True
else:
return False
方法二:
class Solution:
def Find(self, target, array):
row=len(array)
col=len(list(zip(*array)))
i,j=row-1,0
while i>=0 and j<col:
if array[i][j]==target:
return True
elif array[i][j]>target:
i-=1
else:
j+=1
else:
return False