Difficulty
Easy
Language
Python
Solution 1 - Staircase from Bottom-Left
If current < 0, all to the right are negative.
If current < 0, all to the right are negative.
""" 1351.1 - Count Negative Numbers in a Sorted Matrix - Solution 1 - Staircase """
from typing import List
class Solution:
def countNegatives(self, grid: List[List[int]]) -> int:
m, n = len(grid), len(grid[0])
r, c = m - 1, 0
count = 0
while r >= 0 and c < n:
if grid[r][c] < 0:
count += n - c
r -= 1
else:
c += 1
return count