mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
57 lines
2.2 KiB
HTML
57 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> ,且矩阵中 <code>1</code> 的数目可以被 <code>4</code> <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,1,0],[0,0,1]]</span></p>
|
||
|
||
<p><span class="example-io"><b>输出:</b>3</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p><img src="https://assets.leetcode.com/uploads/2024/08/01/image.png" style="width: 400px; height: 105px;" /></p>
|
||
</div>
|
||
|
||
<p><strong class="example">示例 2:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><span class="example-io"><b>输入:</b>grid = [[0,1],[0,1],[0,0]]</span></p>
|
||
|
||
<p><span class="example-io"><b>输出:</b>2</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/08/screenshot-from-2024-07-09-01-37-48.png" style="width: 300px; height: 104px;" /></p>
|
||
</div>
|
||
|
||
<p><strong class="example">示例 3:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><span class="example-io"><b>输入:</b>grid = [[1],[1]]</span></p>
|
||
|
||
<p><span class="example-io"><b>输出:</b>2</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/08/01/screenshot-from-2024-08-01-23-05-26.png" style="width: 200px; height: 70px;" /></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>
|