[LeetCode]303. Range Sum Query
来源:互联网 发布:迅雷9优化版 编辑:程序博客网 时间:2024/06/01 09:58
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.
Example:
Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRange(0, 5) -> -3
Note:
- You may assume that the array does not change.
- There are many calls to sumRange function.
类型:Dynamic Programming
public class NumArray { private int[] sums; public NumArray(int[] nums) { sums = new int[nums.length+1]; for(int i=1; i<nums.length+1; i++) sums[i]=nums[i-1]+sums[i-1]; } public int sumRange(int i, int j) { return sums[j+1]-sums[i]; }}/** * Your NumArray object will be instantiated and called as such: * NumArray obj = new NumArray(nums); * int param_1 = obj.sumRange(i,j); */
注意下标
阅读全文
0 0
- 303.[LeetCode]Range Sum Query
- LeetCode-303. Range Sum Query
- [LeetCode]303. Range Sum Query
- LeetCode#303. Range Sum Query
- leetcode 303. Range Sum Query
- [LeetCode]303. Range Sum Query
- LeetCode 303. Range Sum Query
- LeetCode 303. Range Sum Query
- LeetCode 303. Range Sum Query
- leetcode-303. Range Sum Query
- LeetCode 303. Range Sum Query
- leetcode.303.Range Sum Query
- leetcode 303. Range Sum Query
- leetcode 303. Range Sum Query
- [leetcode]: 303. Range Sum Query
- [Leetcode] 303. Range Sum Query
- [LeetCode]303. Range Sum Query
- leetcode 303. Range Sum Query
- FZU
- 百度面试经历
- 深入理解游戏中寻路算法
- C语言之数组队列
- dfs遍历螺旋矩阵
- [LeetCode]303. Range Sum Query
- web项目与微信对接报错误码48002 Api禁用(一般是管理组类型与Api不匹配,例如普通管理组调用会话服务的Api)
- Linux查看隐藏文件
- 大作业1(画线)
- Linux后台执行程序
- matlab小知识点
- Java设计模式之结构型七大模式
- 数据库注入攻击和防止注入攻击
- JAVA流星雨