2025-07-25 09:29:53 +0000 UTC

Count Negative Numbers in a Sorted Matrix

Code

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