Range Sum Query

来源:互联网 发布:三菱中性笔 知乎 编辑:程序博客网 时间:2024/06/06 08:57

一、题目

英文:Range Sum Query - Immutable

中文:数组指定区间内的元素和

二、内容要求

英文:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.
中文:给定一个数组nums,求出索引i和j之间元素的和,i一定是小于或等于j的

三、示例

Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRange(0, 5) -> -3

四、代码

提示:(1)您可以假设数组没有改变。(2)求和函数有很多种调用。

1.java代码




原创粉丝点击