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

二维数组中的查找

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

相关推荐

ohs的小木屋:比不少实习待遇高了
点赞 评论 收藏
分享
人力小鱼姐:实习经历没有什么含金量,咖啡店员迎宾这种就别写了,其他两段包装一下 想找人力相关的话,总结一下个人优势,结合校园经历里有相关性的部分,加一段自我评价
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务