题解 | #二维数组中的查找#
二维数组中的查找
http://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e
一维查找的延伸,注意边界条件
class Solution:
def Find(self , target: int, array: List[List[int]]) -> bool:
# write code here
m = len(array)
if m:
n = len(array[0])
if m*n == 0:
return False
for y in range(m):
start = 0
end = n - 1
if array[y][start] > target:
break
elif array[y][end] < target:
continue
else:
while start <= end:
x = int((start + end) / 2)
if array[y][x] == target:
return True
elif array[y][x] < target:
start = x + 1
else:
end = x - 1
return False