1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 19:18:14 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/统计有序矩阵中的负数 [count-negative-numbers-in-a-sorted-matrix].html

34 lines
1003 B
HTML
Raw Normal View History

2022-03-27 20:37:52 +08:00
<p>给你一个&nbsp;<code>m&nbsp;* n</code>&nbsp;的矩阵&nbsp;<code>grid</code>,矩阵中的元素无论是按行还是按列,都以非递增顺序排列。&nbsp;请你统计并返回&nbsp;<code>grid</code>&nbsp;<strong>负数</strong> 的数目。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]
<strong>输出:</strong>8
<strong>解释:</strong>矩阵中共有 8 个负数。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>grid = [[3,2],[1,0]]
<strong>输出:</strong>0
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>m == grid.length</code></li>
<li><code>n == grid[i].length</code></li>
<li><code>1 &lt;= m, n &lt;= 100</code></li>
<li><code>-100 &lt;= grid[i][j] &lt;= 100</code></li>
</ul>
<p>&nbsp;</p>
<p><strong>进阶:</strong>你可以设计一个时间复杂度为 <code>O(n + m)</code> 的解决方案吗?</p>