题解 | #二维数组中的查找#

二维数组中的查找

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
全部评论

相关推荐

03-16 13:56
湖南大学 C++
牛客872108596号:到现在没消息是挂了吗查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务