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)/矩阵中战斗力最弱的 K 行 [the-k-weakest-rows-in-a-matrix].html
2022-03-29 12:43:11 +08:00

62 lines
1.6 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>给你一个大小为 <code>m * n</code> 的矩阵 <code>mat</code>,矩阵由若干军人和平民组成,分别用 1 和 0 表示。</p>
<p>请你返回矩阵中战斗力最弱的 <code>k</code> 行的索引,按从最弱到最强排序。</p>
<p>如果第 <em><strong>i</strong></em> 行的军人数量少于第 <em><strong>j</strong></em> 行,或者两行军人数量相同但<em><strong> i</strong></em> 小于 <em><strong>j</strong></em>,那么我们认为第<em><strong> i </strong></em>行的战斗力比第<em><strong> j </strong></em>行弱。</p>
<p>军人 <strong>总是</strong> 排在一行中的靠前位置,也就是说 1 总是出现在 0 之前。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>mat =
[[1,1,0,0,0],
[1,1,1,1,0],
[1,0,0,0,0],
[1,1,0,0,0],
[1,1,1,1,1]],
k = 3
<strong>输出:</strong>[2,0,3]
<strong>解释:</strong>
每行中的军人数目:
行 0 -> 2
行 1 -> 4
行 2 -> 1
行 3 -> 2
行 4 -> 5
从最弱到最强对这些行排序后得到 [2,0,3,1,4]
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>mat =
[[1,0,0,0],
 [1,1,1,1],
 [1,0,0,0],
 [1,0,0,0]],
k = 2
<strong>输出:</strong>[0,2]
<strong>解释:</strong>
每行中的军人数目:
行 0 -> 1
行 1 -> 4
行 2 -> 1
行 3 -> 1
从最弱到最强对这些行排序后得到 [0,2,3,1]
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>m == mat.length</code></li>
<li><code>n == mat[i].length</code></li>
<li><code>2 <= n, m <= 100</code></li>
<li><code>1 <= k <= m</code></li>
<li><code>matrix[i][j]</code> 不是 0 就是 1</li>
</ul>