LeetCode --- 1351. Count Negative Numbers in a Sorted Matrix 解题报告

Posted 杨鑫newlfe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode --- 1351. Count Negative Numbers in a Sorted Matrix 解题报告相关的知识,希望对你有一定的参考价值。

Given a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid.

Example 1:

Input: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]
Output: 8
Explanation: There are 8 negatives number in the matrix.

Example 2:

Input: grid = [[3,2],[1,0]]
Output: 0

Constraints:

  • m == grid.length
  • n == grid[i].length
  • 1 <= m, n <= 100
  • -100 <= grid[i][j] <= 100

Follow up: Could you find an O(n + m) solution?

所有代码均可在Github中找到:

以上是关于LeetCode --- 1351. Count Negative Numbers in a Sorted Matrix 解题报告的主要内容,如果未能解决你的问题,请参考以下文章

1351. Count Negative Numbers in a Sorted Matrix

⭐算法入门⭐《二分枚举》简单13 —— LeetCode 1351. 统计有序矩阵中的负数

LeetCode Count Univalue Subtrees

Leetcode 之Count and Say(35)

LeetCode Count Primes

leetcode 165. 比较版本号