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%)
2
class Solution:
3
def countNegatives(self, grid: List[List[int]]) -> int:
4
count = 0
5

6
for i in grid:
7
low = 0
8
high = len(i) - 1
9

10
while low <= high:
11
mid = (low + high) // 2
12
if i[mid] < 0:
13
high = mid - 1
14
elif i[mid] >= 0:
15
low = mid + 1
16
count += len(i) - low
17
return count

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0