题意:查询一个数组在(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. Android之activity中新建控件

    了解了5大布局,我们会发现这些布局都是静态的,如何让系统自动生成控件呢?这就需要activity来帮忙了 今天我们讲的就是用activity新建布局 用案例来说吧! 实现一个输入行和列自动生成表格并生 ...

  2. Selenium2+python自动化25-js处理日历控件(修改readonly属性)

    前言 日历控件是web网站上经常会遇到的一个场景,有些输入框是可以直接输入日期的,有些不能,以我们经常抢票的12306网站为例,详细讲解如何解决日历控件为readonly属性的问题. 基本思路:先用j ...

  3. Oracle Database常用补丁集Patch号及各版本PSU

    Oracle Database常用补丁集Patch号及各版本PSU------------------------------------------------------------------- ...

  4. Log4j基本用法

    基本使用方法: Log4j由三个重要的组件构成:日志信息的优先级,日志信息的输出目的地,日志信息的输出格式.日志信息的优先级从高到低有ERROR.WARN.INFO.DEBUG,分别用来指定这条日志信 ...

  5. SILVERLIGHT 多维表头、复杂表头 MULTIPLE HEADER

    先上图, 众所周知,利用silverlight datagrid展示数据相当方便,但是想要弄出一个漂亮的表头却要费尽周折.此文的目的就是简要介绍一下利用第三方控件 C1.Silverlight.Fle ...

  6. 【Maven】Eclipse 使用Maven创建SpringMVC Web项目

    创建环境 系统:win 10 软件:eclipse,maven. 创建步骤 创建一个Maven Web项目,可以参照:[Maven]Eclipse 使用Maven创建Java Web项目 添加spri ...

  7. javascript 对象属性的get set访问器写法

    function Person() {     var age = new Date().getFullYear() - 18;     Object.defineProperty(this, &qu ...

  8. 【洛谷P1378】油滴扩展

    搜索-- PS一个坑点:r<=0时并不是舍弃这种情况,而是让r=0 (因为每个点都要放一滴油)(读题啊!) #include<cstdio> #include<cstring& ...

  9. Ajax跨域请求ashx文件与Webservice文件

    前台页面: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1 ...

  10. Webalizer解析nginx基本配置

    先前使用了nginx做tomcat程序负载,后来需要解析日志.查看访问量.后来网上查了下,就使用了这个参考地址: http://daliang1215.iteye.com/blog/618829 .安 ...