Skip to content

Commit 53cde1b

Browse files
committed
1351. Count Negative Numbers in a Sorted Matrix
1 parent 0b93741 commit 53cde1b

File tree

2 files changed

+70
-51
lines changed

2 files changed

+70
-51
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
def countNegatives(self, grid: List[List[int]]) -> int:
3+
return sum(a<0 for i in grid for a in i)
4+
5+
# method 2
6+
class Solution(object):
7+
def countNegatives(self, grid):
8+
i = len(grid)-1
9+
j = 0
10+
count = 0
11+
while i>=0 and j< len(grid[0]):
12+
print(i,j)
13+
if grid[i][j] < 0:
14+
count +=len(grid[0])-j
15+
i -= 1
16+
else:
17+
j +=1
18+
return(count)

0 commit comments

Comments
 (0)