Guest User

Untitled

a guest
Jun 20th, 2022
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1.  
  2. # class Solution:
  3. # def countNegatives(self, grid):
  4. #
  5. # count = 0
  6. # for row in range(0, len(grid)):
  7. #
  8. # for column in range(0, len(grid[row])):
  9. # if grid[row][column] < 0:
  10. # count = count + 1
  11. # return count
  12.  
  13.  
  14. class Solution:
  15. def countNegatives(self, grid):
  16.  
  17. row_len = len(grid[0])
  18. col_len = len(grid)
  19.  
  20. i = 0
  21. j = row_len - 1
  22.  
  23. total = 0
  24.  
  25. while i < col_len and j >= 0:
  26. if grid[i][j] < 0:
  27. total += col_len - i
  28. j -= 1
  29. else:
  30. i += 1
  31. return total
  32.  
  33. d = Solution().countNegatives(grid= [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]])
  34. print(d)
Advertisement
Add Comment
Please, Sign In to add comment