题意:查询一个数组在(i,j]范围内的元素的和。

思路非常简单,做个预处理,打个表就好

拓展:可以使用树状数组来完成该统计,算法复杂度为(logn),该数据结构强力的地方是实现简单,而且能完成实时更新以及上面的统计和

class NumArray {
public:
vector<int> sum;
NumArray(vector<int> &nums) {
sum.push_back();
for(vector<int>::size_type i = ; i< nums.size(); ++i){
int m = sum[i] + nums[i];
sum.push_back(m);
}
} int sumRange(int i, int j) {
return sum[j + ] - sum[i];
}
};

Leetcode 303 Range Sum Query - Immutable的更多相关文章

  1. [LeetCode] 303. Range Sum Query - Immutable (Easy)

    303. Range Sum Query - Immutable class NumArray { private: vector<int> v; public: NumArray(vec ...

  2. [LeetCode] 303. Range Sum Query - Immutable 区域和检索 - 不可变

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  3. LeetCode 303. Range Sum Query – Immutable

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  4. Java [Leetcode 303]Range Sum Query - Immutable

    题目描述: Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inc ...

  5. LeetCode 303. Range Sum Query - Immutable (C++)

    题目: Given an integer array nums, find the sum of the elements between indices iand j (i ≤ j), inclus ...

  6. LeetCode 303 Range Sum Query - Immutable(范围总和查询-永久不变)(*)

    翻译 给定一个整型数组nums,找出在索引i到j(i小于等于j)之间(包含i和j)的全部元素之和. 比如: 给定nums = [-2,0,3,-5,2,-1] sumRange(0, 2) -> ...

  7. leetcode 303. Range Sum Query - Immutable(前缀和)

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  8. 【LeetCode】303. Range Sum Query - Immutable 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 保存累积和 日期 题目地址:https://leetcode. ...

  9. 【一天一道LeetCode】#303.Range Sum Query - Immutable

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 我的个人博客已创建,欢迎大家持续关注! 一天一道le ...

随机推荐

  1. jQuery -> bind / live / delegate 的终结者 - on

    Bind()方法: 给元素绑定事件 形式: .bind(eventType[,eventData],handler(eventObject)) eventType,string类型,一个或多个DOM事 ...

  2. 深入理解JVM内存模型

    1.程序计数器在虚拟机的概念模型里字节码解释器工作时就是通过改变 这个计数器的值来选取下一条需要执行的字节码指令,分支.循环.跳转.异常处理. Java 虚拟机的多线程是通过线程轮流切换并分配处理器执 ...

  3. zabbix网络发现

    zabbix的网络自动发现是一个非常强大的功能,该功能可以完成以下工作 •快速发现并添加主机. •简单的管理. •随着环境的改变而快速搭建监控系统. 网络发现基于以下信息 •ip地址段 •基于服务的F ...

  4. 插件兼容CommonJS, AMD, CMD 和 原生 JS

    模块标准 CommonJS CommonJS 有三个全局变量 module.exports 和 require.但是由于 AMD 也有 require 这个全局变量,故不使用这个变量来进行检测. 如果 ...

  5. 建立自己的git repository

    环境是windows 1.首先安装Git,下载Git安装包,这个google 就好了 2.注册自己的git账号 https://github.com 3.建立仓库 填好名字 最后那个Initializ ...

  6. 尽量少用if else

    Michael Feathers是Object Mentor International公司的技术顾问.他的工作不仅是技术开发,他还参与对世界各地技术团队进行培训.指导等工作.他曾开发了将JUnit迁 ...

  7. STF(SmartPhone Test Farm)Mac版本环境搭建

    它的github页面为: https://github.com/openstf/stf 1.Linux一些基本包的安装: 在控制台分别运行 sudo apt-get update sudo apt-g ...

  8. 工作中遇到的小问题: 做弹幕从数据库取出东西均匀插入marquee中,

    function getFloatContent() { var method = 'GETFLOATCONTENT'; $.ajax({ url: 'api/zhenqiapi.php', data ...

  9. Hibernate之创建命名策略

    在开发软件时,通常会要求每个开发人员遵守共同的命名策略.例如,数据库的表名及字段名的所有字符都要大写,表名以“S”结尾.对于Customer类,对应的数据库表名为CUSTOMERS.为了在映射文件中遵 ...

  10. windows server 2008 - 创建域和本机用户

    /* * ===================================================================================== * Filenam ...