LeetCode 1351.统计有序矩阵中的负数(简单)

python

class Solution:
    def countNegatives(self, grid: List[List[int]]) -> int:
        count = 0
        for i in range(len(grid)):
            for j in range(len(grid[i])):
                if(grid[i][j]<0):
                    break
            if(grid[i][j]<0):
                count += len(grid[i]) - j

        return count

LeetCode 1351.统计有序矩阵中的负数(简单)_第1张图片

 

你可能感兴趣的:(LeetCode刷题,leetcode,算法,职场和发展)