题目描述
题目链接:https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/
解题思路
将矩阵展开成一维数组,用in
判断即可。
class Solution:
def findNumberIn2DArray(self, matrix: List[List[int]], target: int) -> bool:
alist = [i for j in matrix for i in j] # 嵌套for循环,先遍历每一行j
return (target in alist)