Skip to content

Commit

Permalink
1351
Browse files Browse the repository at this point in the history
  • Loading branch information
isinsuarici committed Feb 2, 2022
1 parent a60a52b commit 2de8315
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions E_1351_CountNegativeNumbersinaSortedMatrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution:
def countNegatives(self, grid: List[List[int]]) -> int:
def binary_search(row):
start, end = 0, len(row)
while start<end:
mid = start + (end-start)//2 #floor divison
if row[mid]<0:
end = mid
else:
start = mid+1
return len(row)- start

count = 0
for row in grid:
count += binary_search(row)
return(count)

0 comments on commit 2de8315

Please sign in to comment.