1. 程式人生 > >Lintcode207 Interval Sum II solution 題解

Lintcode207 Interval Sum II solution 題解

修改 sta sum 比較 ray 會有 .com suggest value

【題目描述】

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
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請註明出處。

Lintcode207 Interval Sum II solution 題解