Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # class Solution:
- # def countNegatives(self, grid):
- #
- # count = 0
- # for row in range(0, len(grid)):
- #
- # for column in range(0, len(grid[row])):
- # if grid[row][column] < 0:
- # count = count + 1
- # return count
- class Solution:
- def countNegatives(self, grid):
- row_len = len(grid[0])
- col_len = len(grid)
- i = 0
- j = row_len - 1
- total = 0
- while i < col_len and j >= 0:
- if grid[i][j] < 0:
- total += col_len - i
- j -= 1
- else:
- i += 1
- return total
- d = Solution().countNegatives(grid= [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]])
- print(d)
Advertisement
Add Comment
Please, Sign In to add comment