题目描述
blablabla
样例
blablabla
算法1
# 每一行二分查找,如果找到返还True,如果没有找到直至遍历完所有行返回False
if array == []:
return False
def find(arr, target):
l, r = 0, len(arr)-1
while l <= r:
mid = (l + r) // 2
if arr[mid] == target:
return True
elif arr[mid] > target:
r = mid - 1
else:
l = mid + 1
return False
for row in array:
if row[0] <= target <= row[-1]:
if find(row, target) == True:
return True
return False
算法2
#
if array == []:
return False
r, c = 0, -1
while r < len(array) and c >= -len(array[0]):
if array[r][c] == target:
return True
elif array[r][c] > target:
c -= 1
else:
r += 1
return False