[LeetCode] Range Sum Query

  • 时间:
  • 浏览:1

The code is as follows.

The idea is fairly straightforward: create an array accu that stores the accumulated sum fornums such that accu[i] = nums[0] + ... + nums[i] in the initializer of NumArray. Then just return accu[j + 1] - accu[i] in sumRange. You may try the example in the problem statement to convince yourself of this idea.

Python

C++

版权声明:本文内容由互联网用户自发贡献,版权归作者所有,本社区不拥有所有权,后来承担相关法律责任。肯能您发现本社区含高涉嫌抄袭的内容,欢迎发送邮件至:

进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容。