mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-07 08:21:41 +08:00
存量题库数据更新
This commit is contained in:
@@ -4,15 +4,17 @@
|
||||
<li>Calculate the <strong>sum</strong> of the elements of <code>matrix</code> inside the rectangle defined by its <strong>upper left corner</strong> <code>(row1, col1)</code> and <strong>lower right corner</strong> <code>(row2, col2)</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Implement the NumMatrix class:</p>
|
||||
<p>Implement the <code>NumMatrix</code> class:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>NumMatrix(int[][] matrix)</code> Initializes the object with the integer matrix <code>matrix</code>.</li>
|
||||
<li><code>int sumRegion(int row1, int col1, int row2, int col2)</code> Returns the <strong>sum</strong> of the elements of <code>matrix</code> inside the rectangle defined by its <strong>upper left corner</strong> <code>(row1, col1)</code> and <strong>lower right corner</strong> <code>(row2, col2)</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>You must design an algorithm where <code>sumRegion</code> works on <code>O(1)</code> time complexity.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/14/sum-grid.jpg" style="width: 415px; height: 415px;" />
|
||||
<pre>
|
||||
<strong>Input</strong>
|
||||
@@ -35,7 +37,7 @@ numMatrix.sumRegion(1, 2, 2, 4); // return 12 (i.e sum of the blue rectangle)
|
||||
<li><code>m == matrix.length</code></li>
|
||||
<li><code>n == matrix[i].length</code></li>
|
||||
<li><code>1 <= m, n <= 200</code></li>
|
||||
<li><code>-10<sup>5</sup> <= matrix[i][j] <= 10<sup>5</sup></code></li>
|
||||
<li><code>-10<sup>4</sup> <= matrix[i][j] <= 10<sup>4</sup></code></li>
|
||||
<li><code>0 <= row1 <= row2 < m</code></li>
|
||||
<li><code>0 <= col1 <= col2 < n</code></li>
|
||||
<li>At most <code>10<sup>4</sup></code> calls will be made to <code>sumRegion</code>.</li>
|
||||
|
Reference in New Issue
Block a user