1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/矩形区域不超过 K 的最大数值和 [max-sum-of-rectangle-no-larger-than-k].html
2022-03-29 12:43:11 +08:00

37 lines
1.2 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>给你一个 <code>m x n</code> 的矩阵 <code>matrix</code> 和一个整数 <code>k</code> ,找出并返回矩阵内部矩形区域的不超过 <code>k</code> 的最大数值和。</p>
<p>题目数据保证总会存在一个数值和不超过 <code>k</code> 的矩形区域。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/18/sum-grid.jpg" style="width: 255px; height: 176px;" />
<pre>
<strong>输入:</strong>matrix = [[1,0,1],[0,-2,3]], k = 2
<strong>输出:</strong>2
<strong>解释:</strong>蓝色边框圈出来的矩形区域 <code>[[0, 1], [-2, 3]]</code> 的数值和是 2且 2 是不超过 k 的最大数字k = 2
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>matrix = [[2,2,-1]], k = 3
<strong>输出:</strong>3
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>m == matrix.length</code></li>
<li><code>n == matrix[i].length</code></li>
<li><code>1 <= m, n <= 100</code></li>
<li><code>-100 <= matrix[i][j] <= 100</code></li>
<li><code>-10<sup>5</sup> <= k <= 10<sup>5</sup></code></li>
</ul>
<p> </p>
<p><strong>进阶:</strong>如果行数远大于列数,该如何设计解决方案?</p>