这个题目是来寻找list[list]里是否含有指定的数。对于python来讲就太简单了。把所有的list的数放到一个list里,检测一下就好了。代码如下:
class Solution(object):
def searchMatrix(self, matrix, target):
"""
:type matrix: List[List[int]]
:type target: int
:rtype: bool
"""
list1 = []
for i in matrix:
list1.extend(i)
if target in list1:
return True
else:
return False
本文介绍了一种简单的Python方法,用于在一维列表中查找特定元素。通过将二维列表转换为一维列表,可以轻松地检查目标值是否存在。
169

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



