mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-13 11:21:42 +08:00
add leetcode problem-cn part2
This commit is contained in:
38
算法题(国内版)/problem (Chinese)/最大方阵和 [maximum-matrix-sum].html
Normal file
38
算法题(国内版)/problem (Chinese)/最大方阵和 [maximum-matrix-sum].html
Normal file
@@ -0,0 +1,38 @@
|
||||
<p>给你一个 <code>n x n</code> 的整数方阵 <code>matrix</code> 。你可以执行以下操作 <strong>任意次</strong> :</p>
|
||||
|
||||
<ul>
|
||||
<li>选择 <code>matrix</code> 中 <strong>相邻</strong> 两个元素,并将它们都 <strong>乘以</strong> <code>-1</code> 。</li>
|
||||
</ul>
|
||||
|
||||
<p>如果两个元素有 <strong>公共边</strong> ,那么它们就是 <strong>相邻</strong> 的。</p>
|
||||
|
||||
<p>你的目的是 <strong>最大化</strong> 方阵元素的和。请你在执行以上操作之后,返回方阵的 <strong>最大</strong> 和。</p>
|
||||
|
||||
<p> </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>示例 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> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>n == matrix.length == matrix[i].length</code></li>
|
||||
<li><code>2 <= n <= 250</code></li>
|
||||
<li><code>-10<sup>5</sup> <= matrix[i][j] <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
Reference in New Issue
Block a user