Count Negative Numbers in a Sorted Matrix LeetCode solution in Python
1# Runtime: 252 ms (Top 17.18%) | Memory: 15.1 MB (Top 10.42%)2class Solution:3def countNegatives(self, grid: List[List[int]]) -> int:4count = 056for i in grid:7low = 08high = len(i) - 1910while low <= high:11mid = (low + high) // 212if i[mid] < 0:13high = mid - 114elif i[mid] >= 0:15low = mid + 116count += len(i) - low17return count