mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
61 lines
2.2 KiB
HTML
61 lines
2.2 KiB
HTML
<p>给你一个 <code>m x n</code> 的二进制矩阵 <code>grid</code> 。</p>
|
||
|
||
<p>如果矩阵中一行或者一列从前往后与从后往前读是一样的,那么我们称这一行或者这一列是 <strong>回文</strong> 的。</p>
|
||
|
||
<p>你可以将 <code>grid</code> 中任意格子的值 <strong>翻转</strong> ,也就是将格子里的值从 <code>0</code> 变成 <code>1</code> ,或者从 <code>1</code> 变成 <code>0</code> 。</p>
|
||
|
||
<p>请你返回 <strong>最少</strong> 翻转次数,使得矩阵 <strong>要么</strong> 所有行是 <strong>回文的</strong> ,要么所有列是 <strong>回文的</strong> 。</p>
|
||
|
||
<p> </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> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>m == grid.length</code></li>
|
||
<li><code>n == grid[i].length</code></li>
|
||
<li><code>1 <= m * n <= 2 * 10<sup>5</sup></code></li>
|
||
<li><code>0 <= grid[i][j] <= 1</code></li>
|
||
</ul>
|