【題目描述】
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.
在類的構(gòu)造函數(shù)中給一個整數(shù)數(shù)組, 實現(xiàn)兩個方法query(start, end)和modify(index, value):
對于 query(start,end), 返回數(shù)組中下標(biāo)start到end的和。
對于 modify(index,value), 修改數(shù)組中下標(biāo)為index上的數(shù)為value.
【注】在做此題前,建議先完成以下三題:
【題目鏈接】
www.lintcode.com/en/problem/interval-sum-ii/
【題目解析】
此題屬于比較簡單的題目,同[Interval Sum I]的思路類似,可把query sum和modify結(jié)合起來即可解決問題。
【參考答案】