
# -*- coding:utf-8 -*-
class Solution:
# array 二维列表
def Find(self, target, array):
# write code here
rows = len(array)
cols = len(array[0])
startx = rows - 1
starty = 0
while startx >= 0 and starty <= cols - 1:
if target == array[startx][starty]:
return True
elif array[startx][starty] > target:
startx -= 1
elif array[startx][starty] < target:
starty += 1
return False

本文介绍了一种在二维数组中高效查找目标值的算法。通过从数组的右上角开始,根据目标值与当前元素的比较结果调整搜索方向,实现快速定位。此方法适用于已排序的二维数组,大幅提升了查找效率。

被折叠的 条评论
为什么被折叠?



