Lintcode207 Interval Sum II solution 题解

【题目描述】

Given an integer array in the construct method, implement two methods query(start, end) and modify(index, value):

For query(start,end), return the sum from index start to index end in the given array.

For modify(index,value), modify the number in the given index tovalue

Notice

We suggest you finish problem Segment Tree Build,Segment Tree Query andSegment Tree Modify first.

在类的构造函数中给一个整数数组, 实现两个方法query(start, end)和modify(index, value):

对于 query(start,end), 返回数组中下标startend

对于 modify(index,value), 修改数组中下标为index上的数为value.

【注】在做此题前,建议先完成以下三题:

线段树的构造

线段树的查询

线段树的修改

【题目链接】

www.lintcode.com/en/problem/interval-sum-ii/

【题目解析】

此题属于比较简单的题目,同[Interval Sum I]的思路类似,可把query sum和modify结合起来即可解决问题。

【参考答案】

www.jiuzhang.com/solutions/interval-sum-ii/

作者:程风破浪会有时
链接:https://www.jianshu.com/p/7b7d7d5d151c
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

原文地址:https://www.cnblogs.com/5245a/p/8450405.html

时间: 2024-08-07 10:39:15

Lintcode207 Interval Sum II solution 题解的相关文章

Lintcode: Interval Sum II

Given an integer array in the construct method, implement two methods query(start, end) and modify(index, value): For query(start, end), return the sum from index start to index end in the given array. For modify(index, value), modify the number in t

Lintcode42 Maximum Subarray II solution 题解

[题目描述] Given an array of integers, find two non-overlapping subarrays which have the largest sum.The number in each subarray should be contiguous.Return the largest sum. Notice:The subarray should contain at least one number 给定一个整数数组,找出两个 不重叠 子数组使得它们

Lintcode18 Subsets II solution 题解

[题目描述] Given a list of numbers that may has duplicate numbers, return all possible subsets Notice:Each element in a subset must be in non-descending order.The ordering between two subsets is free.The solution set must not contain duplicate subsets. 给

Lintcode205 Interval Minimum Number solution 题解

[题目描述] Given an integer array (index from 0 to n-1, where n is the size of this array), and an query list. Each query has two integers[start, end]. For each query, calculate the minimum number between index start and end in the given array, return th

Lintcode16 Permutations II solution 题解

[题目描述] Given a list of numbers with duplicate number in it. Find all unique permutations. 给出一个具有重复数字的列表,找出列表所有不同的排列. [题目链接] http://www.lintcode.com/en/problem/permutations-ii/ [题目解析] 跟 Permutations的解法一样,就是要考虑"去重".先对数组进行排序,这样在DFS的时候,可以先判断前面的一个数是否

Lintcode70 Binary Tree Level Order Traversal II solution 题解

[题目描述] Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). 给出一棵二叉树,返回其节点值从底向上的层次序遍历(按从叶节点所在层到根节点所在的层遍历,然后逐层从左往右遍历) [题目链接] www.lintcode.com/en/problem/binary

Lintcode34 N-Queens II solution 题解

[题目描述] Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions. 根据n皇后问题,现在返回n皇后不同的解决方案的数量而不是具体的放置布局. [题目链接] http://www.lintcode.com/en/problem/n-queens-ii/ [题目解析] 这道题跟NQueens的解法完全一样(具

Lintcode54 String to Integer II solution 题解

[题目描述] Implement function atoi to convert a string to an integer.If no valid conversion could be performed, a zero value is returned.If the correct value is out of the range of representable values, INT_MAX (2147483647) or INT_MIN (-2147483648) is re

Lintcode36 Reverse Linked List II solution 题解

[题目描述] Reverse a linked list from position m to n. Notice:Given m, n satisfy the following condition: 1 ≤ m ≤ n ≤ length of list. 翻转链表中第m个节点到第n个节点的部分 注意:m,n满足1 ≤ m ≤ n ≤ 链表长度 [题目链接] http://www.lintcode.com/en/problem/reverse-linked-list-ii/ [题目解析] 反转