Skip to content

Commit a70aa9a

Browse files
authored
Create negnumbersmatrix.py
1 parent 99f53a4 commit a70aa9a

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def countNegatives(self, grid):
3+
rows, cols = len(grid), len(grid[0])
4+
count = 0
5+
row, col = rows - 1, 0
6+
7+
while row >= 0 and col < cols:
8+
if grid[row][col] < 0:
9+
count += cols - col
10+
row -= 1
11+
else:
12+
col += 1
13+
14+
return count

0 commit comments

Comments
 (0)