leetcode之Search a 2D Matrix

来源:互联网 发布:erp软件命令 编辑:程序博客网 时间:2024/05/18 21:43

这个题目是来寻找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



0 0
原创粉丝点击