#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param target int整型
# @param array int整型二维数组
# @return bool布尔型
#
class Solution:
def Find(self , target: int, array: List[List[int]]) -> bool:
# write code here
if not array or not array[0]:
return False
rows,cols = len(array), len(array[0])
# 从右上角开始
row, col = 0, cols - 1
while row < rows and col >= 0:
current = array[row][col]
if current == target:
return True
elif current > target:
# 当前元素太大,向左移动(排除当前列)
col -= 1
else:
# 当前元素太小,向下移动(排除当前行)
row += 1
return False