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/

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容