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

34 lines
1003 B
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<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>