lintcode 38. 搜索二维矩阵 II

难度:

1. Description

38. 搜索二维矩阵 II

2. Solution

  • python
class Solution:
    """
    @param matrix: A list of lists of integers
    @param target: An integer you want to search in matrix
    @return: An integer indicate the total occurrence of target in the given matrix
    """
    def searchMatrix(self, matrix, target):
        # write your code here
        if len(matrix)==0:
            return 0
        if len(matrix[0])==0:
            return 0
        m = len(matrix)
        n = len(matrix[0])
        cnt = 0
        for i in range(n):
            if targetmatrix[m-1][i]:
                continue
            for j in range(m):
                if target == matrix[j][i]:
                    cnt+=1
        return cnt

3. Reference

  1. https://www.lintcode.com/problem/search-a-2d-matrix-ii/description?_from=ladder

你可能感兴趣的:(lintcode 38. 搜索二维矩阵 II)