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)/最少翻转次数使二进制矩阵回文 I [minimum-number-of-flips-to-make-binary-grid-palindromic-i].html
2024-08-06 08:46:50 +08:00

61 lines
2.2 KiB
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 x n</code>&nbsp;的二进制矩阵&nbsp;<code>grid</code>&nbsp;</p>
<p>如果矩阵中一行或者一列从前往后与从后往前读是一样的,那么我们称这一行或者这一列是 <strong>回文</strong> 的。</p>
<p>你可以将 <code>grid</code>&nbsp;中任意格子的值 <strong>翻转</strong>&nbsp;,也就是将格子里的值从 <code>0</code>&nbsp;变成 <code>1</code>&nbsp;,或者从 <code>1</code>&nbsp;变成 <code>0</code>&nbsp;</p>
<p>请你返回 <strong>最少</strong>&nbsp;翻转次数,使得矩阵 <strong>要么</strong>&nbsp;所有行是 <strong>回文的</strong>&nbsp;,要么所有列是 <strong>回文的</strong>&nbsp;</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>grid = [[1,0,0],[0,0,0],[0,0,1]]</span></p>
<p><span class="example-io"><b>输出:</b>2</span></p>
<p><b>解释:</b></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/07/screenshot-from-2024-07-08-00-20-10.png" style="width: 420px; height: 108px;" /></p>
<p>将高亮的格子翻转,得到所有行都是回文的。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>grid = </span>[[0,1],[0,1],[0,0]]</p>
<p><span class="example-io"><b>输出:</b>1</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/07/screenshot-from-2024-07-08-00-31-23.png" style="width: 300px; height: 100px;" /></p>
<p>将高亮的格子翻转,得到所有列都是回文的。</p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>grid = [[1],[0]]</span></p>
<p><span class="example-io"><b>输出:</b>0</span></p>
<p><strong>解释:</strong></p>
<p>所有行已经是回文的。</p>
</div>
<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;= 2 * 10<sup>5</sup></code></li>
<li><code>0 &lt;= grid[i][j] &lt;= 1</code></li>
</ul>