1 # -*- coding:utf-8 -*- 2 """用row和col两参数逐行或逐列遍历数组""" 3 class Solution: 4 # array 二维列表 5 def Find(self, target, array): 6 # write code here 7 rows = len(array)#首先确定数组的维度 8 cols = len(array[0]) 9 row=0 10 col = cols-1 11 while row < rows and col>=0: 12 if target == array[row][col]: #若找到了直接return结束程序 13 return True 14 elif target <= array[row][col]: 15 col -= 1 16 else: 17 row += 1 18 return False