题解 | #二维数组中的查找#
二维数组中的查找
http://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e
刷题第一天打卡:
解法1:for循环遍历
class Solution:
def Find(self , target: int, array: List[List[int]]) -> bool:
# write code here
i = 0
if array == [[]]:
return False
while i < len(array):
if array[i][0] <= target <= array[i][-1]:
if target in array[i]:
return True
else:
i += 1
return False
超时,故舍弃
解法2:list.extend()函数
https://www.runoob.com/python/att-list-append.html
class Solution:
def Find(self , target: int, array: List[List[int]]) -> bool:
# write code here
result = []
for i in range(len(array)):
result.extend(array[i])
if target in result:
return True
else:
return False