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)/最大方阵和 [maximum-matrix-sum].html
2022-03-29 12:43:11 +08:00

39 lines
1.6 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>n x n</code>&nbsp;的整数方阵&nbsp;<code>matrix</code>&nbsp;。你可以执行以下操作&nbsp;<strong>任意次</strong>&nbsp;</p>
<ul>
<li>选择&nbsp;<code>matrix</code>&nbsp;&nbsp;<strong>相邻</strong>&nbsp;两个元素,并将它们都 <strong>乘以</strong>&nbsp;<code>-1</code>&nbsp;</li>
</ul>
<p>如果两个元素有 <strong>公共边</strong>&nbsp;,那么它们就是 <strong>相邻</strong>&nbsp;的。</p>
<p>你的目的是 <strong>最大化</strong>&nbsp;方阵元素的和。请你在执行以上操作之后,返回方阵的&nbsp;<strong>最大</strong>&nbsp;和。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/07/16/pc79-q2ex1.png" style="width: 401px; height: 81px;">
<pre><b>输入:</b>matrix = [[1,-1],[-1,1]]
<b>输出:</b>4
<b>解释:</b>我们可以执行以下操作使和等于 4
- 将第一行的 2 个元素乘以 -1 。
- 将第一列的 2 个元素乘以 -1 。
</pre>
<p><strong>示例&nbsp;2</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/07/16/pc79-q2ex2.png" style="width: 321px; height: 121px;">
<pre><b>输入:</b>matrix = [[1,2,3],[-1,-2,-3],[1,2,3]]
<b>输出:</b>16
<b>解释:</b>我们可以执行以下操作使和等于 16
- 将第二行的最后 2 个元素乘以 -1 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == matrix.length == matrix[i].length</code></li>
<li><code>2 &lt;= n &lt;= 250</code></li>
<li><code>-10<sup>5</sup> &lt;= matrix[i][j] &lt;= 10<sup>5</sup></code></li>
</ul>