class Solution:
# array 二维列表
def Find(self, target, array):
# write code here
rows=len(array)-1
cols=len(array[0])-1
i=rows #从二维数组的左下角那个数字开始
j=0
while i>=0 and j<=cols:
if target > array[i][j]: #说明在右边
j += 1 #行不变,列向右移动一位
elif target < array[i][j]:
i -= 1
else:
return True
return False
# # Find(9, [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) TypeError: Find() missing 1 required positional argument: 'array'
# mat=[[1,2,3],[4,5,6],[7,8,9]]
# s=Solution()
# s.Find(1,mat)#插入代码片
#单独这一段执行不了的
if __name__ == '__main__': #作为脚本直接执行
mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
s=Solution()
print(s.Find(1,mat))
print(array[0]) -------》 [1, 2, 3]
print(len(array[0])) -------》3