leetcode Range Sum Query 2D – Immutable

leetcode Range Sum Query 2D – Immutable

Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).

Range Sum Query 2D
The above rectangle (with the red border) is defined by (row1, col1) = (2, 1) and (row2, col2) = (4, 3), which contains sum = 8.

Example:

Note:

  1. You may assume that the matrix does not change.
  2. There are many calls to sumRegion function.
  3. You may assume that row1 ≤ row2 and col1 ≤ col2.

题目地址  leetcode Range Sum Query 2D – Immutable

题意:

给定一个矩阵,和两个矩阵的坐标(row1,col1),(row2,col2),让你计算他们之间元素的和

思路:

和之前的那题leetcode Range Sum Query – Immutable很像,只不过这次用二维数组进行和的存储。

记得多减去的要加回来~

Code:

 

本博客若无特殊说明则由 hrwhisper 原创发布
转载请点名出处:细语呢喃 > leetcode Range Sum Query 2D – Immutable
本文地址:https://www.hrwhisper.me/leetcode-range-sum-query-2d-immutable/

听说长得好看的已经打赏了

Leetcode , , . permalink.

4 thoughts on “leetcode Range Sum Query 2D – Immutable

  1. 深更半夜睡不着,,事情好多,自己的博客都快有1个月没更新了,,把评论从disqus换到多说了,前者好像让大家都没有什么评论的兴趣(误)我们实验室也有一个女孩要去RUC了,前天才知道-_-||,还是直博,囧。毕设选题,hr选的什么呢?死活也不做什么管理系统什么的,计划去做hadoop,实现一些算法。和在友盟的之前实验室的学长聊,他强烈推荐做spark。只是spark虽然性能好,但是资料少,学scala函数式编程心里也是挺忐忑的~毕设还是保险点。睡不着啊睡不着,睡不着啊睡不着,还是第一次失眠呢

Leave a Reply

Your email address will not be published. Required fields are marked *