Leetcode no. 303
来源:互联网 发布:淘宝店铺改域名 编辑:程序博客网 时间:2024/06/05 11:36
303. Range Sum Query - Immutable
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.
public class NumArray { private int[] res; public NumArray(int[] nums) { for (int i=1; i<nums.length; i++){ nums[i]+=nums[i-1]; } this.res= nums; } public int sumRange(int i, int j) { if (i==0) return res[j]; return res[j]-res[i-1]; }}// Your NumArray object will be instantiated and called as such:// NumArray numArray = new NumArray(nums);// numArray.sumRange(0, 1);// numArray.sumRange(1, 2);
0 0
- Leetcode no. 303
- LeetCode--No.303--Range Sum Query - Immutable
- LeetCode No.303 Range Sum Query - Immutable
- LeetCode No.11 ~No.12
- Leetcode NO.78 Subsets
- Leetcode NO.77 Combinations
- Leetcode NO.46 Permutations
- 【leetcode】No. 235 LCABST
- LeetCode no. 35
- Leetcode no. 37
- Leetcode no. 279
- Leetcode no. 335
- Leetcode no. 283
- Leetcode no. 181 (sql)
- Leetcode no. 40
- Leetcode no. 238
- Leetcode no. 26
- Leetcode no. 80
- GDSOI 2016 T1 互补约数
- view的setTag() 和 getTag()应用
- 关系型数据库和非关系型数据库
- ThreadLocal 与 Request 和 Session 之关联
- 打开Word提示向程序发送命令时出现问题怎么办?
- Leetcode no. 303
- 培训行业
- 动态存储分配及深复制 —我的数组类
- elastic资料整理
- 数据结构----完全二叉树和满二叉树以及前序、中序、后序遍历
- 使用ThinkPHP框架快速搭建网站(通俗易懂)
- Java 实现导出excel表 POI
- 语义化标签
- 树-Path Sum II(指定和,求根到叶子的路径)