1. 程式人生 > >Lintcode205 Interval Minimum Number solution 題解

Lintcode205 Interval Minimum Number solution 題解

簡書 calculate ray 描述 ger build calc dex nsh

【題目描述】

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 the result list.

Notice:We suggest you finish problem Segment Tree Build,Segment Tree Query and Segment Tree Modify first.

給定一個整數數組(下標由 0 到 n-1,其中 n 表示數組的規模),以及一個查詢列表。每一個查詢列表有兩個整數[start, end]。 對於每個查詢,計算出數組中從下標 start 到 end 之間的數的最小值,並返回在結果列表中。

【註】:在做此題前,建議先完成以下三道題線段樹的構造,線段樹的查詢及線段樹的修改。

【題目鏈接】

www.lintcode.com/en/problem/interval-minimum-number/

【題目解析】

這道題目是篩選出Interval數組中的最小值,存入新數組。因此,聯想到Segment Tree Build和Segment Tree Query系列的題目,對於Interval的處理,使用線段樹是非常有效的方法。之前我們創建的線段樹,有max和count兩個properties。參照max這個參數,可以考慮在這道題增加一個min的參數,代表每個結點的最小值。

【參考答案】

www.jiuzhang.com/solutions/interval-minimum-number/



作者:程風破浪會有時
鏈接:https://www.jianshu.com/p/01f28f824379
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請註明出處。

Lintcode205 Interval Minimum Number solution 題解